How do I initialize CKRecord with zoneID and recordID?
I am currently creating a solution to sync records Core Data
with CloudKit
.
I need help figuring out what I want to do with CKRecord
.
I checked the Apple CloudKit documentation, experimented and searched the web, but I didn't find the answer I want.
I would like to initialize the CKRecord with zoneID
as well recordID
, which I would provide in the init method.
The initializer seems to be forcing me to choose between the two. i want to create my own ZoneID (not using default) and also set recordID
instead of being auto-generated.
Is it possible?
source to share
You can specify the zone ID and the record ID, but you need to do this in three steps:
First create CKRecordZoneID
with your zone id and user:
let ckRecordZoneID = CKRecordZoneID(zoneName: "myZone", ownerName: CKOwnerDefaultName)
Then you can create CKRecordID
with the required post id and specify yours CKRecordZoneID
:
let ckRecordID = CKRecordID(recordName: recordIDString, zoneID: ckRecordZoneID)
Finally, you can create CKRecord
using this post id:
let ckRecord = CKRecord(recordType: myRecordType, recordID: ckRecordID)
source to share