How to initialize CKRecord with both zoneID and recordID?

孤街浪徒 提交于 2019-12-06 01:25:18

问题


I'm currently building a solution to sync Core Data records to CloudKit.

I need help to find out it what I want to do with CKRecord is feasible.

I’ve checked the Apple CloudKit documentation, experiment and searched the web, but I didn’t find the kind of answer I want.

I would like to initialize the CKRecord with having zoneID and also recordID that I would supply in init method.
The initializer seems to force me to choose between the two. I want to create my own ZoneID (not using default), and also set the recordID instead of having it being autogenerated.

Would that be possible?


回答1:


You can specify both a zone ID and a record ID, but you need to do it in three steps:

First, create a CKRecordZoneID with your zone ID and user:

let ckRecordZoneID = CKRecordZoneID(zoneName: "myZone", ownerName: CKOwnerDefaultName)

Then you can created a CKRecordID with your required record ID and specifying your CKRecordZoneID:

let ckRecordID = CKRecordID(recordName: recordIDString, zoneID: ckRecordZoneID)

Finally you can create the CKRecord using that record ID:

let ckRecord = CKRecord(recordType: myRecordType, recordID: ckRecordID)


来源:https://stackoverflow.com/questions/45429133/how-to-initialize-ckrecord-with-both-zoneid-and-recordid

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!