condition on app launching
I have a classic core data stack with one persistent store and two contexts (main context for UI, and the private one for editing, deleting, etc.). Also I use NSFetchedResultsController
for fetching coredata objects and representing it in a table view and everything works fine, except one case.
On app startup (in viewDidLoad
method) I send a request to a server to get new items for syncing with a local database, and on a response I just add or delete an items on a private context, and at the same time NSFetchedResultsController
is trying to do fetch from a main context (calls performFetch
in viewDidLoad
), and as a result objects are faulted and cannot be represented in a table view and app just crash ( NSManagedObjectContextDidSave
notification is not even sent).
I was trying to fix this issue by a different ways, but all of these ways are bad I believe. For example: adding sleep(1)
before deleting an object fixes the problem, or executing a method which sends a request to the server in DispatchQueue.main.async
block fixes this as well, but I cannot be sure that this will resolve the problem in 100% cases. So what is the best way to fix this issue wihout changing the core data stack model and I know, that my problem won't happen on a stack with parent/chield contexts.
上一篇: 低通滤波器强大
下一篇: 应用程序启动条件