Hi!
I have the "-com.apple.CoreData.ConcurrencyDebug 1" argument set in the schema to check if I have some CoreData concurrency problems.
I don't know why but this code give me an Multithreading_Violation_AllThatIsLeftToUsIsHonor error.
Do you think I did something wrong with this code?
private func loadSigns(searchTerm: String) {
let privateMOC = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
privateMOC.parent = managedObjectContext
let fetchRequest: NSFetchRequest = Sign.fetchRequest()
let predicate = NSPredicate(format: "name CONTAINS[cd] %@", searchTerm, 0)
fetchRequest.predicate = predicate
let sortDescriptor = NSSortDescriptor(key: "name", ascending: true)
fetchRequest.sortDescriptors = [sortDescriptor]
let asynchronousFetchRequest = NSAsynchronousFetchRequest(fetchRequest: fetchRequest) {(result:NSAsynchronousFetchResult!) -> Void in
print("request done")
}
do {
_ = try privateMOC.execute(asynchronousFetchRequest) as? NSPersistentStoreAsynchronousResult
} catch {
let nserror = error as NSError
fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
}
}
I also tried to incapsulate the code inside the perform method of the privateMOC but I still have the Multithreading_Violation_AllThatIsLeftToUsIsHonor error:
private func loadSigns(searchTerm: String) {
let privateMOC = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
privateMOC.parent = managedObjectContext
privateMOC.perform {
let fetchRequest: NSFetchRequest = Sign.fetchRequest()
let predicate = NSPredicate(format: "name CONTAINS[cd] %@", searchTerm, 0)
fetchRequest.predicate = predicate
let sortDescriptor = NSSortDescriptor(key: "name", ascending: true)
fetchRequest.sortDescriptors = [sortDescriptor]
let asynchronousFetchRequest = NSAsynchronousFetchRequest(fetchRequest: fetchRequest) {(result:NSAsynchronousFetchResult!) -> Void in
print("request done")
}
do {
_ = try privateMOC.execute(asynchronousFetchRequest) as? NSPersistentStoreAsynchronousResult
} catch {
let nserror = error as NSError
fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
}
}
}
Any idea?
Thank you