Re: Newbie question: instantiate a class in its header file OR in IB
Re: Newbie question: instantiate a class in its header file OR in IB
- Subject: Re: Newbie question: instantiate a class in its header file OR in IB
- From: Jens Alfke <email@hidden>
- Date: Tue, 24 Jun 2008 22:32:53 -0700
On 24 Jun '08, at 8:34 PM, JArod Wen wrote:
I am a cocoa newbie from Java. Recently I found an example code in
which the instance of a class is defined in its own class's header
file, as following:
@interface AppController : NSObject {
// Instance variables here
}
AppController *appController;
That's not valid code as you wrote it … I think you meant to put an
"@end" after the "}"? In that case, "appController" is a declaration
of a global variable, a pointer to an AppController instance. This is
a pretty common thing to do: the global variable points to the
singleton instance of AppController, as a quick way to let other code
call methods on it. Usually AppController initializes the variable
like so:
- (void) awakeFromNib {
appController = self;
}
Now if some other code in the app wants to, say, open the preferences
panel, it can call [appController openPrefs: self].
—Jens_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden