Skip to content

Instantly share code, notes, and snippets.

@garsdle
Last active April 13, 2018 00:08
Show Gist options
  • Save garsdle/c9ba81475f4e8ad70e297af3a600f3d3 to your computer and use it in GitHub Desktop.
Save garsdle/c9ba81475f4e8ad70e297af3a600f3d3 to your computer and use it in GitHub Desktop.
SeparateMapping
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