我在删除发送到服务器端的一些数据后尝试保存核心数据上下文。我在尝试context.save()
时遇到此错误Error Domain=NSCocoaErrorDomain Code=132001 "(null)" UserInfo={message=attempt to recursively call -save: on the context aborted, stack trace=(
0 CoreData 0x0000000185e8b22c <redacted> + 156
1 ??? 0x0000000106b0caec 0x0 + 4407216876
2 ??? 0x0000000106b0cbd0 0x0 + 4407217104
3 Bakery 0x0000000100d64868 main + 0
4 Bakery 0x0000000100d601b0 _T0Ix_IyB_TR + 48
5 libdispatch.dylib 0x00000001020352cc _dispatch_call_block_and_release + 24
6 libdispatch.dylib 0x000000010203528c _dispatch_client_callout + 16
7 libdispatch.dylib 0x0000000102046b58 _dispatch_root_queue_drain + 1016
8 libdispatch.dylib 0x00000001020466f4 _dispatch_worker_thread3 + 136
9 libsystem_pthread.dylib 0x00000001832eb06c _pthread_wqthread + 1268
10 libsystem_pthread.dylib 0x00000001832eab6c start_wqthread + 4
)}
电话:
func sendBenefitsIfNeeeded(_ status:Reachability.Connection){
let hasInternetConnection = status != .none
if hasInternetConnection {
self.syncBenefits { _ in
self.deleteBenefitsAlreadySynced()
}
} }
context.save()
上的错误private func syncBenefits(完成:@escaping(AppError?) - &gt; Void){ syncEmployees {_ in let request = NSFetchRequest(entityName:&#34; BenefitEntity&#34;)
request.returnsObjectsAsFaults = false
do {
let result = try self.context.fetch(request)
guard let resultArray = result as? [NSManagedObject] else {
return
}
for data in resultArray {
let registration = (data.value(forKey: "registration") as? Int) ?? 0
self.grantBenefit(employeeRegistration: registration) { error, message in
guard let benefitSended = self.fetchBenefit(byRegistration: registration) else {
return
}
benefitSended.synced = true
DispatchQueue.main.async {
do {
try self.context.save() // ERROR HERE!
} catch {
}
completion(error)
}
}
}
} catch {
print("Failed")
}
}
}
我不知道发生了什么:(
PS:在更改互联网连接时调用该函数的侦听器调用syncBenefits。
#EDIT:我尝试使用DispatchQueue.main.async(主线程)但发生了同样的错误:(