UIManagedDocument proper initialization and wait until it is ready

I'm trying to use CoreData with an UIManagedDocument and I know it takes a little while until it is ready to go, and I also know that it fires a notification when it's ready. I want to display the app when its ready, is it convenient to do it this way?

What would be the standard approach (time and way) for initializing a UIManagedDocument and waiting until it's ready to go?

What happens with applications that show data from the very start?

Upvotes: 2

Views: 1186

Answers (2)

svena
svena

Reputation: 2779

Apple recommends you listen for UIDocumentStateChangedNotification to react on state changes on your document. That includes both when your document is open and ready for you to proceed, as well as steps that you want to take when there was an error saving the document for example.

While this is about Document based application, it also applies to UIManagedDocument.

See Document-Based App Programming Guide for iOS.

Why I personally favor this approach is because it allows me to adjust UI depending on document state. And it allows me to react based on the state of more than one document combined. Something which would be much trickier to do with completion handlers.

Upvotes: 3

Jody Hagins
Jody Hagins

Reputation: 28349

Both interfaces for creating and opening a UIManagedDocument have a callback block.

I suggest having a document property that is not set until the completion handler runs. That way you know for sure that the document is open and ready to go.

I would display the app, with no data, and let the open/fetch ovulate the data when it is ready.

If I do it when starting the app, I go ahead and load up the app, and when the data is ready, it populates the view... but only by loading just enough to get started, the rest of the fetch happens in the background.

Opening a file should not take long... the time consuming part is then loading data. If you must, you could show a splash screen on start up. Apple's stuff shows an image that is similar to a blank app... see how iTunesU shows the blank bookcase while it starts up, then populates it with your stuff.

Some people play an opening cut scene for a few seconds at the beginning that masks the startup sequence. I guess it could be appropriate, depending on your app. That seems more acceptable in graphics oriented games.

Upvotes: 1

Related Questions