Skip to content

Instantly share code, notes, and snippets.

@sergdort
Last active December 16, 2015 13:43
Show Gist options
  • Save sergdort/f38110981de143c407a0 to your computer and use it in GitHub Desktop.
Save sergdort/f38110981de143c407a0 to your computer and use it in GitHub Desktop.
extension User {
@NSManaged var lastName: String?
@NSManaged var name: String?
@NSManaged var userId: NSNumber?
@NSManaged var createdEvents: NSSet?
@NSManaged var homeCity: City?
}
extension User {
override class var map:[String : String] {
return [ "userId" : "id",
"lastName" : "last_name",
"homeCity" : "home_city",
"createdEvents" : "events"]
}
override class var relatedByAttribute: String {
return "userId"
}
override class var relatedJsonKey: String {
return "id"
}
}
...
let data:NSData = ...
let context = ..
do {
let user:User? = try SwiftImport<User>.importObject
<^> context
<*> JSONObject -<< JSONObjectWithData -<< data
} catch {
// handle error
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment