View Full Version : Help with Cocoa app initialization method

Jun 26, 2008, 10:37 PM
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?


Jun 26, 2008, 10:57 PM
Generally you'd run most of your app's initialization either from -awakeFromNib (for objects in nib files) or NSApp's delegate in -applicationWillFinishLaunching:

Jun 26, 2008, 11:00 PM
+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.

Jun 26, 2008, 11:43 PM
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;