Skip to content

Instantly share code, notes, and snippets.

@aaronksaunders
Last active March 3, 2016 07:00
Show Gist options
  • Select an option

  • Save aaronksaunders/d1eee541265d00f8289e to your computer and use it in GitHub Desktop.

Select an option

Save aaronksaunders/d1eee541265d00f8289e to your computer and use it in GitHub Desktop.
class Player : NSObject {
var objectId: String?
var teamName : NSString?
var team :Team?
var firstName : NSString?
var lastName : NSString?
//Inivitation.swift
override func hostToKinveyPropertyMapping() -> [NSObject : AnyObject]! {
return [
"objectId" : KCSEntityKeyId,
"teamName" : "teamName",
"team" : "team",
"firstName" : KCSUserAttributeGivenname,
"lastName" :KCSUserAttributeSurname,
]
}
override class func kinveyPropertyToCollectionMapping() -> [NSObject : AnyObject]! {
return [
"team" : "Teams",
]
}
// Here you tell Kinvey which class to map the team property to. This
// is how it knows how to build the object when it fetches it from the server.
override class func kinveyObjectBuilderOptions() -> [NSObject : AnyObject]! {
let referenceMap:[NSObject : AnyObject] = [
"team" : Team.self
]
return [
KCS_REFERENCE_MAP_KEY : referenceMap
]
}
}
let store = KCSLinkedAppdataStore.storeWithOptions([
KCSStoreKeyCollectionName : "Players",
KCSStoreKeyCollectionTemplateClass : Player.self
])
let player = Player()
player.firstName = _username
player.lastName = "Last Name"
player.team = _team
player.teamName = _team.name!
store.saveObject(
player,
withCompletionBlock: { (objectsOrNil: [AnyObject]!, errorOrNil: NSError!) -> Void in
if errorOrNil != nil {
//save failed
NSLog("Save failed, with error: %@", errorOrNil.localizedFailureReason!)
} else {
//save was successful
NSLog("Successfully saved event (id='%@').", (objectsOrNil[0] as! NSObject).kinveyObjectId())
}
},
withProgressBlock: nil
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment