Help with Cocoa app initialization method

Discussion in 'Mac Programming' started by swac, Jun 26, 2008.

  1. macrumors newbie

    Oct 25, 2007
    I'm learning how to make applications Cocoa, and the first app I'm trying to make is a basic four-function calculator. I'm having trouble getting my initialization method to run so that I can initialize a few objects and other variables. I tried looking up an initialization method, and the only one I found was

    + (void)initialize

    The description of this method seems to be what I'm looking for, so I added in what I wanted to add, yet it doesn't seem to be executing that method when I launch the program. Am I using the method incorrectly/is there some other method that I should be using?

  2. macrumors 68030


    Sep 13, 2001
    Portland, OR
    Generally you'd run most of your app's initialization either from -awakeFromNib (for objects in nib files) or NSApp's delegate in -applicationWillFinishLaunching:
  3. macrumors 6502

    Jul 25, 2006
    +initialize is called before the class or object receives its first message. This likely isn't the place you want to initialize variables for your objects, since you can't get access to ivars from a class method. -init, -awakeFromNib, or -applicationDidFinishLaunching: are typical places for doing this.
  4. macrumors regular

    Jan 18, 2006
    I usually call -init to do all my initializations. I used to put everything in -awakeFromNib, but I feel like a noob putting everything in there. Use something like this to initialize your variables.
    - (id)init {
        if(self = [super init]) {
            //your initialization code goes here
        return self;

Share This Page