This file contains hidden or 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
let predicate = NSPredicate(value: true) | |
let query = CKQuery(recordType: "Movie", predicate: predicate) | |
let operation = CKQueryOperation(query: query) |
This file contains hidden or 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
NotificationCenter.default.addObserver(self, | |
selector: #selector(startDiscoveryProcess), | |
name: Notification.Name.CKAccountChanged, | |
object: nil) |
This file contains hidden or 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
private func updateUserRecord(_ userRecord: CKRecord, with avatarURL: URL) { | |
userRecord["avatar"] = CKAsset(fileURL: avatarURL) | |
CKContainer.default().publicCloudDatabase.save(userRecord) { _, error in | |
guard error == nil else { | |
// top-notch error handling | |
return | |
} | |
print("Successfully updated user record with new avatar") |
This file contains hidden or 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
CKContainer.default().requestApplicationPermission(.userDiscoverability) { status, error in | |
guard status == .granted, error == nil else { | |
// error handling voodoo | |
return | |
} | |
CKContainer.default().discoverUserIdentity(withUserRecordID: recordID) { identity, error in | |
guard let components = identity?.nameComponents, error == nil else { | |
// more error handling magic | |
return |
This file contains hidden or 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
CKContainer().default().discoverAllIdentities { identities, error in | |
guard let identities = identities, error == nil else { | |
// awesome error handling | |
return | |
} | |
print("User has \(identities.count) contact(s) using the app:") | |
print("\(identities)") | |
} |
This file contains hidden or 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
// `recordID` is the record ID returned from CKContainer.fetchUserRecordID | |
CKContainer.default().publicCloudDatabase.fetch(withRecordID: recordID) { record, error in | |
guard let record = record, error == nil else { | |
// show off your error handling skills | |
return | |
} | |
print("The user record is: \(record)") | |
} |
This file contains hidden or 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
CKContainer.default().fetchUserRecordID { recordID, error in | |
guard let recordID = recordID, error == nil else { | |
// error handling magic | |
return | |
} | |
print("Got user record ID \(recordID.recordName).") | |
} |
This file contains hidden or 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
container.privateCloudDatabase.fetchAllRecordZones { zones, error in | |
guard let zones = zones, error == nil else { | |
// error handling magic | |
return | |
} | |
print("I have these zones: \(zones)") | |
} |
This file contains hidden or 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
@IBAction func titleFieldAction(_ sender: Any) { | |
guard let title = titleField.text else { return } | |
record["title"] = title as CKRecordValue | |
} |
This file contains hidden or 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
enum MovieKey: String { | |
case title | |
case releaseDate | |
case location | |
case rating | |
} |