-
-
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)
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 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