Skip to content

mtj0928/userinfo-representable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

@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.

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.

let userInfo: [AnyHashable: Any] = foo.convertToUserInfo()

About

userinfo-representable helps a conversion from userInfo to your types.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages