• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Newbie question: instantiate a class in its header file OR in IB
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Newbie question: instantiate a class in its header file OR in IB (From: JArod Wen <email@hidden>)

  • Prev by Date: Re: Newbie question: instantiate a class in its header file OR in IB
  • Next by Date: Re: Allocating outlets from NIB file
  • Previous by thread: Re: Newbie question: instantiate a class in its header file OR in IB
  • Next by thread: NSPredicateEditor
  • Index(es):
    • Date
    • Thread