Alex G
Alex G

Reputation: 21

How do I execute code on Application startup in a Document-based app

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?

Upvotes: 2

Views: 417

Answers (1)

user142019
user142019

Reputation:

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

Upvotes: 5

Related Questions