https://github.com/sajjon/makros
Collection of Swift Macros
https://github.com/sajjon/makros
Last synced: 11 months ago
JSON representation
Collection of Swift Macros
- Host: GitHub
- URL: https://github.com/sajjon/makros
- Owner: Sajjon
- Created: 2023-06-10T06:10:44.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-06-12T10:03:55.000Z (about 3 years ago)
- Last Synced: 2025-08-17T18:06:53.629Z (11 months ago)
- Language: Swift
- Size: 27.3 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# `@DataStorage`
Makes it easy to work with `Data`.
## No args
```swift
@DataStorage
struct DataHolder {}
```
Expands to:
```swift
struct DataHolder {
let data: Data
init(data: Data) {
self.data = data
}
}
```
## `byteCount`
```swift
@DataStorage(named: "key", byteCount: 32)
public struct PublicKey {}
```
Expands to:
```swift
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)"
}
}
}
```