Last active
January 7, 2016 16:09
-
-
Save zntfdr/08f020b88fa2f174d3b3 to your computer and use it in GitHub Desktop.
Medium Post - Parsing JSON Objects in Swift 2 [2/3] https://medium.com/@zntfdr/parsing-json-objects-in-swift-2-c402cb90ac00
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
// Some model | |
struct MyModel { | |
let name: String | |
let number: Int | |
let date: NSDate | |
} | |
// Conforming to the new protocol | |
extension MyModel: JSONParser { | |
static func obtainModel(from json: JSON) -> MyModel? { | |
guard let | |
// parse json and construct MyModel | |
else { return nil } | |
return MyModel(name: name, number: number, date: date) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment