Created
October 24, 2016 06:17
-
-
Save feighter09/23b9172f5b0072e81f021e3413be385a to your computer and use it in GitHub Desktop.
Revisions
-
feighter09 revised this gist
Oct 24, 2016 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ extension Person: DefaultConvertible { private static let firstNameKey = "first_name" private static let lastNameKey = "last_name" -
feighter09 created this gist
Oct 24, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ // Conform to DefaultConvertible 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 } }