Created
January 20, 2016 21:57
-
-
Save NSExceptional/0384fb9801411f2eb536 to your computer and use it in GitHub Desktop.
An example of how to use Mantle in Swift, assuming you have a bridging header that #imports Mantle.h
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
class MYModel: MTLModel, MTLJSONSerializing { | |
@objc private(set) var name: String? | |
@objc private(set) var identifier: String? | |
@objc private(set) var count: Int = 0 | |
class func JSONKeyPathsByPropertyKey() -> [NSObject : AnyObject]! { | |
return ["name": "model.name", | |
"identifier": "model.id", | |
"count": "model.c"] | |
} | |
} | |
let dict = ["model": ["name": "ThePantsThief", "id": "abcde12345", "count": 21]] | |
let model = try? MTLJSONAdapter.modelOfClass(MYModel.self, fromJSONDictionary: dict) | |
let name = model?.name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment