Created
October 24, 2016 06:17
-
-
Save feighter09/23b9172f5b0072e81f021e3413be385a to your computer and use it in GitHub Desktop.
This file contains 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
extension Person: DefaultConvertible { | |
private static let firstNameKey = "first_name" | |
private static let lastNameKey = "last_name" | |
private static let ageKey = "age" | |
var serialized: [String : AnyObject] { | |
return | |
[ | |
Person.firstNameKey: firstName as AnyObject, | |
Person.lastNameKey: lastName as AnyObject, | |
Person.ageKey: age as AnyObject | |
] | |
} | |
init?(dictionary: [String : AnyObject]) | |
{ | |
guard let firstName = dictionary[Person.firstNameKey] as? String, | |
let lastName = dictionary[Person.lastNameKey] as? String, | |
let age = dictionary[Person.ageKey] as? Int | |
else { return nil } | |
self.firstName = firstName | |
self.lastName = lastName | |
self.age = age | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment