okay, this problem has been solved, I was noticed that I was using -com.apple.CoreData.ConcurrencyDebug 1 for debugging my core data thread process, and there is an issue where my NSManagedObjectContext was defined at the main thread.
the process that my core data processes occurred at background thread, so the exc_breakpoint appears because there is a violation in using dispatch in my core data process. I have understood this by reading about core data multithreading rules.
how I solve this problem by using performAndWait for my NSManagedObjectContext if I want still processing in the background thread, but if I change the process to the main thread it doesn't need to use performAndWait.
...
DispatchQueue.global(qos: .background).async {
...
//fetch the previous data before replace or save the new one
let context = self.managedObjectContext
context.performAndWait {
let fetchRequest: NSFetchRequestSomeEntityModel = SomeEntityModel.fetchRequest()
fetchRequest.predicate = NSPredicate(format: "id=%@", "001")
let fetchResult = try context.fetch(fetchRequest)
...
}
...
}
...
...
...
lazy var managedObjectContext: NSManagedObjectContext = {
let coordinator = self.persistentStoreCoordinator
var managedObjectContext = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType)
managedObjectContext.persistentStoreCoordinator = coordinator
return managedObjectContext
}()
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags: