What is the correct way to tell when an NSArrayController is finished loading its content from a persistent store?

StackOverflow https://stackoverflow.com/questions/922913

Question

What's the best way to know when my array controller that is bound to my core data store is done loading its content?

I've got some methods (i.e. awakeFromNib) that rely on the array controller having its content, but most of the time the array controller doesn't have its content yet when awakeFromNib is being called on that object.

I want to delay my actions until I know the controller has all of its content.

Was it helpful?

Solution

Moving that code to -windowDidLoad is usually a safe bet, it's called after the window is fully loaded compared to -awakeFromNib where you can potentially run into problems because the order on which it's called on all the objects in your nib is not defined.

In general it's a good idea to make a mental note of all the initialization you're doing, what parts need a UI to work correctly, what parts can be delayed until the user performs an action, and so on. For example, it's good to delay tasks like doing a Core Data fetch until the last minute, in case you ever have a window that's not opened until the user requests it. On the other hand, sometimes you'll be working with an object like an outline view that needs its data source to be pre-populated for persistence methods to work.

Once you know what you're doing and in what order it needs to be done, you can choose some combination of init, awakeFromNib, yyyWillLoad, or xxxDidLoad and you'll take care of a lot of bugs like this before they have a chance to cause trouble.

OTHER TIPS

See Theocacao for a discussion about this problem

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top