-
-
Save ccabanero/a78827f0fa13ac498a14 to your computer and use it in GitHub Desktop.
CloudKit: How to query a record from a Container's Public Database Using NSPredicate (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]; | |
//predicate for query | |
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"address = '123 Beggers Canyon, Tatooine'", nil]; | |
//create query | |
CKQuery *query = [[CKQuery alloc] initWithRecordType:@"POI" predicate:predicate]; | |
//execute query | |
[publicDatabase performQuery:query inZoneWithID:nil completionHandler:^(NSArray *results, NSError *error) { | |
//handle query error | |
if(error) { | |
NSLog(@"Uh oh, there was an error querying ... %@", error); | |
} else { | |
//handle query results | |
if([results count] > 0) { | |
//iterate query results | |
for(CKRecord *record in results) { | |
NSLog(@"Query was successfully"); | |
NSLog(@"Title: %@", record[@"title"]); | |
NSLog(@"Description: %@", record[@"description"]); | |
NSLog(@"Address: %@", record[@"address"]); | |
NSLog(@"Locations: %@", record[@"locations"]); | |
} | |
//handle no query results | |
} else { | |
NSLog(@"Query returned zero results"); | |
} | |
} | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment