• 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: Global in NSApplication
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Global in NSApplication


  • Subject: Re: Global in NSApplication
  • From: Jens Alfke <email@hidden>
  • Date: Tue, 26 Jan 2010 20:42:57 -0800

Even easier, use the Singleton design pattern and implement a +sharedInstance class method in your class. This is how existing singletons like NSFileManager work.

--Jens   {via iPhone}


On Jan 26, 2010, at 6:17 PM, Murat Konar <email@hidden> wrote:

Read up on categories. Then make the instance of your Debug class a static variable in your category implementation file, and use a method you added to NSApplication via your category to return it.

<http://en.wikipedia.org/wiki/Objective-C#Categories>

_murat


On Jan 26, 2010, at 6:05 PM, BareFeet wrote:

Hi all,

I've created a "Debug" class in my app, which contains an instance variable and several methods. I want to add this to my application but can't see how.

I can add it to MyDocument class like this:

- (id)init
{
  self = [super init];
  if (self) {
   // other stuff
      debug = [Debug new];
  }
  return self;
}

- (void) dealloc
{
   // other stuff
   [debug release];
   [super dealloc];
}

But I want a global instance for the application as a whole. How do I do this? Do I have to subclass NSApplication just to create a global variable?

I want to be able to call it from any class in my app, such as:

[[NSApp debug] myMethod];

Please reply to the list.

Thanks,
Tom
BareFeet

--
Comparison of SQLite GUI tools:
http://www.tandb.com.au/sqlite/compare/?ml

_______________________________________________

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

_______________________________________________

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
_______________________________________________

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: 
 >Global in NSApplication (From: BareFeet <email@hidden>)
 >Re: Global in NSApplication (From: Murat Konar <email@hidden>)

  • Prev by Date: Re: What is the equivalent of SetSystemUIMode() in Leopard and above?
  • Next by Date: Context menu on NSOutlineView, which row is active/selected?
  • Previous by thread: Re: Global in NSApplication
  • Next by thread: Re: Global in NSApplication
  • Index(es):
    • Date
    • Thread