-
-
Save ccabanero/e0f72d1067ba69eb996a to your computer and use it in GitHub Desktop.
CloudKit: How to query a record from a Container's Public Database Using NSPredicate (Swift)
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 | |
let defaultContainer: CKContainer = CKContainer.defaultContainer() | |
//get the PublicDatabase inside the Container | |
let publicDatabase: CKDatabase = defaultContainer.publicCloudDatabase | |
//predicate for query | |
let predicateForAddress = NSPredicate(format: "address = '123 Beggers Canyon, Tatooine'", argumentArray: nil) | |
//create query | |
let query = CKQuery(recordType: "POI", predicate: predicateForAddress) | |
//execute query | |
publicDatabase.performQuery(query, inZoneWithID: nil) { (resultsArray, queryError) -> Void in | |
if queryError != nil { | |
println("Uh oh, there was an error querying ...") | |
println(queryError.localizedDescription) | |
} | |
if resultsArray != nil { | |
for result in resultsArray { | |
let record: CKRecord = result as CKRecord | |
println(record.objectForKey("title")) | |
println(record.objectForKey("description")) | |
println(record.objectForKey("address")) | |
println(record.objectForKey("location")) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment