• 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: Scott Ribe <email@hidden>
  • Date: Wed, 27 Jan 2010 09:37:20 -0700
  • Thread-topic: Global in NSApplication

Well, even simpler, you could just use C without fancy singletons, as in:

Debug *gDebug = nil;

int main(int argc, char *argv[])
{
    gDebug = [[Debug alloc] init];
    return NSApplicationMain(argc,  (const char **) argv);
}

Then in any file where you want to use it, put "extern Debug *gDebug;". Or
even just include that line at the end of Debug.h.

I toss this out just to remind you that Objective-C includes C, so you
shouldn't forget C techniques. Or, alternatively, if you don't really know
C, you should try to find some time to learn it. For instance, Objective-C
includes no specific way to declare a global variable simply because C
already does so.

Of course this code does not necessarily *prevent* you from making multiple
Debug instances, but neither does the code Graham posted if you try to call
[Debug sharedDebug] from multiple threads. To really prevent it, if
necessary, for a shared library perhaps, takes a bit more work. But if it's
your own class, it might be good enough to just have a "don't do that"
attitude, (or a check in Debug -init that throws an exception) ;-)

--
Scott Ribe
email@hidden
http://www.killerbytes.com/
(303) 722-0567 voice


_______________________________________________

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

  • Follow-Ups:
    • Re: Global in NSApplication
      • From: Graham Cox <email@hidden>
    • Re: Global in NSApplication
      • From: Jens Alfke <email@hidden>
References: 
 >Re: Global in NSApplication (From: BareFeet <email@hidden>)

  • Prev by Date: Re: AppleEvent memory leak
  • Next by Date: Re: What is the equivalent of SetSystemUIMode() in Leopard and above?
  • Previous by thread: Re: Global in NSApplication
  • Next by thread: Re: Global in NSApplication
  • Index(es):
    • Date
    • Thread