Makros

main

Collection of Swift Macros
Sajjon/Makros

@DataStorage

Makes it easy to work with Data.

No args

@DataStorage
struct DataHolder {}

Expands to:

struct DataHolder {
	let data: Data
	
	init(data: Data) {
		self.data = data
	}
}

byteCount

@DataStorage(named: "key", byteCount: 32)
public struct PublicKey {}

Expands to:

public struct PublicKey {
	public static let byteCount = 32
	public let key: Data
	
	public init(key: Data) throws {
		guard key.count == Self.byteCount else {
			throw InvalidByteCount(actual: key.count)
		}
		self.key = key
	}
}

extension PubliKey {
	struct InvalidByteCount: Swift.Error, CustomStringConvertible {
		let actual: Int
		var description: String {
			"Invalid byteCount, expected: \(PublicKey.byteCount), but got: \(actual)"
		}
	}
}

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

Last updated: Fri Oct 18 2024 16:30:57 GMT-0900 (Hawaii-Aleutian Daylight Time)