views:

123

answers:

1

I have a Cocoa document-based application.

When the app launches, I want it to execute some code, which will create a dictionary that I need to be accessible to any document in the application, but I only want the dictionary created when I start the app, not when a new document is opened. Currently I have one controller class, which is instantiated both when the application starts and when new documents are opened.

How do I do this?

+5  A: 

Use this:

- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
    //Your code here
}

in your application delegate.

It will also work for iPhone.

Edited according to Peter's comment

Time Machine
I don't think that would work because each time a new document is created, it is making a new instance of my controller class, and would thus not have the dictionary created when the class is instantiated at the App's start
Alex G
Add it to your application delegate, or to an object in MainMenu.xib (which is only loaded once)
Time Machine
On the Mac, it should be a notification-handler method: `- (void) applicationDidFinishLaunching:(NSNotification *)notification`
Peter Hosey