Skip to content

Conversation

@hex2f
Copy link

@hex2f hex2f commented Mar 28, 2022

This is probably far from the best way to do something like this, may even be possible in the original package with the methods provided, but I couldn't find a way to do it. Just thought i'd share this as a PR in case anyone finds it useful and wants to refine the concept to be merged into the main branch. If not, feel free to close c:

Example of StrictSerializedTransformable

  • Like SerializedTransformable but for non-optional types
 class IntToStringTransformer: StrictTransformable {
    static func transformFromJSON(value: Int) -> String {
        return String(value)
    }
    
    static func transformToJSON(value: String) -> Int {
        return Int(value) ?? 0
    }
 }
 // Usage of `StrictSerializedTransformable`
 struct User: Serializable {
     @StrictSerializedTransformable<IntToStringTransformer>
     var id: String
 } 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant