gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 05:48:33 24 4
gpt4 key购买 nike

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

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

这似乎工作得很好,但我收到警告:'init(recordType:zoneID:)' 已弃用:使用 init(recordType:recordID:) + CKRecord.ID(zoneID:) 代替

如果我使用这些方法,我想我必须这样做:

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 是否有特定原因?

最佳答案

自定义区域无法绕过此问题。如果您不想分配 recordName 值,可以向其传递 UUID().uuidString

Record ID objects are normally created automatically when you create a new record, but [...] you must create record ID objects when you want to save a record in a zone other than the default zone.

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

关于ios - 如何在自定义区域中创建 CKRecord 而无需指定记录名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55904084/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com