Last active
March 3, 2016 07:00
-
-
Save aaronksaunders/d1eee541265d00f8289e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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 | |
| ] | |
| } | |
| } |
This file contains hidden or 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
| 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