Skip to content

Instantly share code, notes, and snippets.

@ccabanero
Last active August 29, 2015 14:07
Show Gist options
  • Save ccabanero/f83a8a0e3fd3d546c31f to your computer and use it in GitHub Desktop.
Save ccabanero/f83a8a0e3fd3d546c31f to your computer and use it in GitHub Desktop.
CloudKit: How to fetch a record from a Container's Public Database with a known Record Id (Objective-C)
//get the Container for the App
CKContainer *defaultContainer = [CKContainer defaultContainer];
//get the PublicDatabase inside the Container
CKDatabase *publicDatabase = [defaultContainer publicCloudDatabase];
//create the target record id you will use to fetch by
CKRecordID *wellKnownID = [[CKRecordID alloc] initWithRecordName:@"1"];
//fetch the target record using it's record id
[publicDatabase fetchRecordWithID:wellKnownID completionHandler:^(CKRecord *record, NSError *error) {
//handle error
if(error) {
NSLog(@"Uh oh, there was an error ... %@", error);
} else {
NSLog(@"Fetched record by Id 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