An open API service indexing awesome lists of open source software.

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

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)"
}
}
}
```