Skip to content

Instantly share code, notes, and snippets.

@zntfdr
Last active January 7, 2016 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zntfdr/08f020b88fa2f174d3b3 to your computer and use it in GitHub Desktop.
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
// 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