Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mtj0928/userinfo-representable
userinfo-representable helps a conversion from userInfo to your types.
https://github.com/mtj0928/userinfo-representable
Last synced: about 2 months ago
JSON representation
userinfo-representable helps a conversion from userInfo to your types.
- Host: GitHub
- URL: https://github.com/mtj0928/userinfo-representable
- Owner: mtj0928
- License: mit
- Created: 2023-11-21T23:50:39.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-17T14:43:53.000Z (9 months ago)
- Last Synced: 2024-09-18T08:44:40.151Z (3 months ago)
- Language: Swift
- Homepage:
- Size: 9.77 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `userinfo-representable`
`userinfo-representable` helps a conversion from `userInfo` to your types.
## Usage
Define your types with attaching `@UserInfoRepresentable`.
Like this example, `@UserInfoRepresentable` can be nested.```swift
@UserInfoRepresentable
struct Foo {
var number: Int
@UserInfoKey("custom key") var text: String
var bar: Bar
}@UserInfoRepresentable
struct Bar {
let value: String
}
```And then, you can parse `userInfo` like this.
```swift
let userInfo: [AnyHashable: Any] = [
"number": 123,
"custom key": "text",
"bar": [
"value": "bar"
],
]
let foo = try Foo(userInfo: userInfo)
```And, you can also convert the type to `userInfo`.
```swift
let userInfo: [AnyHashable: Any] = foo.convertToUserInfo()
```