내 응용 프로그램에서 operation.recordChangedBlock {}
이 func fetchZoneChanges(database: CKDatabase, databaseTokenKey: String, zoneIDs: [CKRecordZoneID], completion: @escaping() -> Void)
으로 끝나면 내 Core Data 데이터베이스의 coreData 레코드가 CloudKit에서 수신 된 새 이름 값으로 업데이트됩니다 . 재귀 호출 시도 -save : CloudKit 레코드가 변경된 후 Core Data viewContext를 저장할 때 중단 된 컨텍스트에서
오류 시도
재귀 - 저장 호출 : 문맥 내가 컨텍스트를 저장하기 위해 노력하고있어 때가 나타납니다 중단에. 내 응용 프로그램에서func saveViewContext() { let context = self.getViewContext() if context.hasChanges { do { try context.save() } catch { // Replace this implementation with code to handle the error appropriately. // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. let nserror = error as NSError fatalError("Unresolved error \(nserror), \(nserror.userInfo)") } } } func getViewContext() -> NSManagedObjectContext { return self.persistentContainer.viewContext }
모든
viewContext
호출 메인 스레드에서 만든 : 여기
func updateCoreDataRecord(editedRecord: Record, newName: String, handleComplete_RecordEditedInCoreData:(()->())) {
let record_RecordID = editedRecord.recordID!
let request: NSFetchRequest<Record> = Record.fetchRequest()
request.predicate = NSPredicate(format: "recordID = %@", record_RecordID)
do {
let results = try self.viewContext?.fetch(request)
if results?.count == 1 {
let recordToUpdate = results![0]
recordToUpdate.setValue(newName, forKey: "name")
DispatchQueue.main.async { // Here I receive the error when editing goes from CloudKit
self.saveViewContext()
}
handleComplete_RecordEditedInCoreData()
}
} catch {
print(error)
}
}
은 다른 관련 기능입니다. 오류가 발생할 수 있다고 생각합니다.
그리고 오류는 saveViewContext
방법으로 연결됩니다. 확실하지는 않지만 동시성 문제 일 수 있다고 생각하지만 해결 방법을 모르겠습니다.
CloudKit 레코드를 업데이트 할 때이 오류가 발생하지 않도록 코드를 어떻게 다시 작성해야합니까? 주 대기열에서 실행되도록 모든 호출을 래핑하려고했으나 도움이되지 않았습니다.
I는 동일한 updateCoreDataRecord()
방법을 사용하고, 사용자 장치에서 코어 데이터 레코드를 변경하고,이 에러 발생하지. CloudKit의 Record Changes를 operation.recordChangedBlock {} 내에 수신 할 때만이 오류가 발생합니다. 여기서 레코드에 대한 핵심 데이터 업데이트를 수행합니다.