Last active
April 13, 2018 00:08
-
-
Save garsdle/c9ba81475f4e8ad70e297af3a600f3d3 to your computer and use it in GitHub Desktop.
SeparateMapping
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct User { | |
let id: Int | |
let name: String | |
} | |
class UserMapper { | |
func map(_ dictionary: [String: Any]) -> User? { | |
guard let id = dictionary["id"] as? Int else { return nil } | |
guard let name = dictionary["user_name"] as? String else { return nil } | |
return User(id: id, name: name) | |
} | |
} | |
let bobUser = UserMapper().map(userDictionary) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment