如何使用zoneID和recordID初始化CKRecord? [英] How to initialize CKRecord with both zoneID and recordID?
问题描述
我目前正在构建一个解决方案,以将核心数据
记录同步到 CloudKit
。
I'm currently building a solution to sync Core Data
records to CloudKit
.
我需要帮助来找出我想对 CKRecord
做什么。
I need help to find out it what I want to do with CKRecord
is feasible.
我检查了Apple CloudKit文档,进行了实验并搜索了网络,但找不到所需的答案。
I’ve checked the Apple CloudKit documentation, experiment and searched the web, but I didn’t find the kind of answer I want.
我想使用 zoneID
和 recordID $来初始化CKRecord。 c $ c>我将在init方法中提供。
初始化程序似乎迫使我在两者之间进行选择。我
想创建自己的ZoneID(不使用默认值),并设置 recordID
而不是自动生成。
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.
可能吗?
推荐答案
您可以同时指定区域ID和记录ID,但是您需要分三步进行操作:
You can specify both a zone ID and a record ID, but you need to do it in three steps:
首先,创建 CKRecordZoneID
使用您的区域ID和用户:
First, create a CKRecordZoneID
with your zone ID and user:
let ckRecordZoneID = CKRecordZoneID(zoneName: "myZone", ownerName: CKOwnerDefaultName)
然后,您可以创建一个 CKRecordID
以及所需的记录ID和指定您的 CKRecordZoneID
:
Then you can created a CKRecordID
with your required record ID and specifying your CKRecordZoneID
:
let ckRecordID = CKRecordID(recordName: recordIDString, zoneID: ckRecordZoneID)
最后,您可以创建 CKRecord
使用该记录ID:
Finally you can create the CKRecord
using that record ID:
let ckRecord = CKRecord(recordType: myRecordType, recordID: ckRecordID)
这篇关于如何使用zoneID和recordID初始化CKRecord?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!