views:

327

answers:

1

Hi,

I have setup coredata in my appDelegate, but it first loads the mainWindow.xib and the corresponding controllers+views in that xib file. Those controllers need to have a managedObjectContext to load properly. And after the xib is unarchived it runs the code in my appDelegate.

How can i setup my coredata and then load the mainWIndow.xib? Or just make sure coredata is initialized properly before unarchiving my mainWindows.xib?

+2  A: 

You could override awakeFromNib on your UIApplicationDelegate subclass, and setup Core Data there. This method will be called once all objects has been unarchived from your nib file, but before their instances begin to do their work. See awakeFromNib as your last chance to tweak any behavior before the instances start running.

Observe:

  • When overriding awakeFromNib you must call [super awakeFromNib], or else your superclass might not initialize properly.
  • The order of the calls to awakeFromNib is undefined, so you may never send messages to any other objects from the same Nib from within awakeFromNib. As a bonus this also means that awakeFromNib is guaranteed to run before any other object in the same Nib needs your services and sends any messages to you.
PeyloW
It seems that, using awakeFromNib in my AppDelegate is sufficient enough.
Ton