Skip to content

Instantly share code, notes, and snippets.

@feighter09
Created October 24, 2016 06:17
Show Gist options
  • Save feighter09/23b9172f5b0072e81f021e3413be385a to your computer and use it in GitHub Desktop.
Save feighter09/23b9172f5b0072e81f021e3413be385a to your computer and use it in GitHub Desktop.
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