-
-
Save ccabanero/8a41a0ef181a12e9eb7c to your computer and use it in GitHub Desktop.
CloudKit: How to update a record in a Container's Public Database (Objective-C)
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
//get the Container for the App | |
CKContainer *defaultContainer = [CKContainer defaultContainer]; | |
//get the PublicDatabase inside the Container | |
CKDatabase *publicDatabase = [defaultContainer publicCloudDatabase]; | |
//create a record id for the target record we want to fetch and then update | |
CKRecordID *wellKnownID = [[CKRecordID alloc] initWithRecordName:@"1"]; | |
//fetch the target record using it's id | |
[publicDatabase fetchRecordWithID:wellKnownID completionHandler:^(CKRecord *record, NSError *error) { | |
//handle fetch error | |
if(error) { | |
NSLog(@"Uh oh, there was an error fetching ... %@", error); | |
} else { | |
//update a property | |
record[@"address"] = @"123 Beggers Canyon, Tatooine";; | |
//save the update back to the target database | |
[publicDatabase saveRecord:record completionHandler:^(CKRecord *record, NSError *error) { | |
//handle error | |
if(error) { | |
NSLog(@"Uh oh, there was an error updating ... %@", error); | |
} else { | |
NSLog(@"Updated record successfully"); | |
NSLog(@"Title: %@", record[@"title"]); | |
NSLog(@"Description: %@", record[@"description"]); | |
NSLog(@"Address: %@", record[@"address"]); | |
NSLog(@"Locations: %@", record[@"locations"]); | |
} | |
}]; | |
} | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment