My app depends on the UIManagedDocuments being open. Therefore I basically don't want the user to do anything unless the documents are open. The problem is that opening closed documents is asynchronous. What is the best way to go about this to make sure the user does not enter data to be saved before the UIManagedDocuments are open? I can think of two possible solutions:
1) Should I just wrap every call accessing the UIManagedDocuments in a check to see if it is open and run the code on the completion handler of opening a closed document? This way doesn't seem ideal because the user may do something and expect the results to be saved but it won't be saved yet.
2) The other approach I thought of is to stall the app somehow to wait for documents to open. But I read somewhere that it is bad to block the main thread to wait for the document to open. Can I somehow make the main thread do the opening itself? Or is that bad too?
Another question I have is, if I open all the documents upon loading my app (initial launch), will they stay open until the app is terminated? Or can the documents close at any time for undetermined reasons?
In short, you need to redesign your UI and/or stop using
UIManagedDocument
. Your Application Launch should be designed so that it can wait for the Core Data stack to be initialized. If you are not doing that now you need to redesign the launch of your application.Further,
UIManagedDocument
should not be used as your primary Core Data stack.UIManagedDocument
should only be used when you are building a document based application. If you build a proper Core Data stack yourself you will eliminate the need for the asynchronous start up.However you still want to disconnect your app launch from the data display because of migrations, iCloud integration, etc. All of which can take human perceivable amounts of time and you don't want them blocking the UI.