-
-
Save ccabanero/838c1cfc48924f6b9eca 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 (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 | |
//create the target record id you will use to fetch by | |
let wellKnownID: CKRecordID = CKRecordID(recordName: "1") | |
//fetch the target record using it's record id | |
publicDatabase.fetchRecordWithID(wellKnownID, completionHandler: { (record, error) -> Void in | |
if error != nil { | |
println("Uh oh, there was an error fetching...") | |
println(error.localizedDescription) | |
} | |
if record != nil { | |
println("Fetched record by Id Successflly") | |
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