如何将ckrecords从默认区域迁移到自定义区域?

时间:2017-04-10 05:58:50

标签: ios cloudkit

我需要迁移记录,因为'CKFetchRecordChangesOperation'不能用于默认记录。我应该逐个迁移它还是有任何方法可以自动进行迁移?

1 个答案:

答案 0 :(得分:1)

是的,需要一个接一个地完成。您需要从旧区域获取所有内容,然后为新的自定义区域创建一个新的区域,如下所示:

func newRecord(from record: CKRecord, newZone: CKRecordZone) -> CKRecord {

    let recordID = CKRecordID(recordName: record.recordID.recordName, zoneID: newZone.zoneID)
    let newRecord = CKRecord(recordType: "Goal", recordID: recordID)

    newRecord["startDate"] = record["startDate"]
    newRecord["endDate"] = record["endDate"]
    newRecord["hours"] = record["hours"]

    return newRecord
}

并保存到CKDatabase