如何在自定义区域中创建CKRecord而无需指定记录名称?

问题描述 投票:0回答:1

我使用以下代码在自定义私有CKRecord中创建CKRecordZone

let noteZoneID = CKRecordZone.ID(zoneName: CloudKitManager.noteZoneName,
                                 ownerName: CKCurrentUserDefaultName)
return CKRecord(recordType: Note.recordType, zoneID: noteZoneID)

这似乎工作得很好,但我得到一个警告:'init(recordType:zoneID:)' is deprecated: Use init(recordType:recordID:) + CKRecord.ID(zoneID:) instead

如果我改用这些方法,我想我必须做以下事情:

let noteZoneID = CKRecordZone.ID(zoneName: CloudKitManager.noteZoneName,
                                 ownerName: CKCurrentUserDefaultName)
let recordID = CKRecord.ID(recordName: "UniqueRecordName", zoneID: noteZoneID)
return CKRecord(recordType: Note.recordType, recordID: recordID)

我对这种方法的问题是突然我负责创建一个独特的recordName,我不明白为什么会这样。是否有另一种创建记录的方法可以消除这种责任?我的应用程序代码应该提出recordName的具体原因吗?

ios swift cloudkit
1个回答
0
投票

没有办法绕过自定义区域。如果你不想指定recordName值,你可以传递一个UUID().uuidString

创建新记录时通常会自动创建记录ID对象,但是当您要将记录保存在默认区域以外的区域时,必须创建记录ID对象。

https://developer.apple.com/documentation/cloudkit/ckrecord/id

© www.soinside.com 2019 - 2024. All rights reserved.