Makes it easy to work with Data
.
@DataStorage
struct DataHolder {}
Expands to:
struct DataHolder {
let data: Data
init(data: Data) {
self.data = data
}
}
@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)"
}
}
}