Hi,
I think I tried everything the last days, but I am stuck.
I like to use a NSAsynchronousFetchRequest and populate a tableview.
It looks as it is working, but when I enable the debug option -com.apple.CoreData.ConcurrencyDebug 1. I get an error when I try to execute the fetch request. And it makes no difference if I try it on the main thread or on the private thread.
crash here → try backgroundContext.execute(asynchronousFetchRequest)
EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
here the sample code - near the same as in the book
// Creates asynchronousFetchRequest
with the fetch request and the completion closure
let asynchronousFetchRequest = NSAsynchronousFetchRequest(fetchRequest: fetchRequest) { asynchronousFetchResult in
// Retrieves an array of dogs from the fetch result `finalResult`
guard let result = asynchronousFetchResult.finalResult as? [DOG] else { return }
// Dispatches to use the data in the main queue
DispatchQueue.main.async {
// Do something
self.dogs.removeAll()
// Iterates the result of the private context
for dog in result {
// Retrieves the ID of the entity
let objectID = dog.objectID
// Creates a new dog entity queue-safe
guard let queueSafeDog = self.persistentContainer.viewContext.object(with: objectID) as? DOG else { continue }
// Adds to the array
self.dogs.append(queueSafeDog)
}
self.tableView.reloadData()
}
}
do {
// Executes `asynchronousFetchRequest`
let backgroundContext = persistentContainer.newBackgroundContext()
try backgroundContext.execute(asynchronousFetchRequest)
} catch let error {
print("NSAsynchronousFetchRequest error: \(error)")
}
}
is this schema flag unusable with AsyncFetchRequest?
Regards
Oliver