userinfo-representable

1.0.2

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

What's New

1.0.2

2024-03-17T14:43:53Z
  • Add a license

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()

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

Last updated: Fri Oct 18 2024 15:26:14 GMT-0900 (Hawaii-Aleutian Daylight Time)