• 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 Object
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Global Object


  • Subject: Re: Global Object
  • From: Tom Jones <email@hidden>
  • Date: Sat, 28 Nov 2009 09:19:12 -0800

Thanks,
I found this (http://codeendeavor.com/archives/535) nice wrapper for ASL and I wanted to see how I could incorporate it in to my app. Since this is a foundation tool I wanted to init it in my "myTestApp.m" main function, and be able to call "[log info:@"Log Stuff"];" in any of my classes. I have never really done this before. Should I just re-init it in each of my classes?

Thanks,
tom



On Nov 27, 2009, at 11:10 PM, Jens Alfke wrote:

>
> On Nov 26, 2009, at 9:18 AM, Tom Jones wrote:
>
>> I thought I could just create a Global variable but that does not work.
>
> Did you make it a pointer? You can't directly declare instances of any Cocoa classes, only pointers to them.
>
> So
> 	MyCocoaClass gFoo;
> is a syntax error, while
> 	MyCocoaClass *gFoo;
> works.
>
> Of course, you need some initialization code that allocates a new object and assigns it to foo. And you have to be sure that this code will run before anyone else tries to use gFoo. This can be problematic. Putting this code into your app delegate's awakeFromNib method is often sufficient, via something like this:
>
> 	- (void) awakeFromNib {
> 		gFoo = [[MyCocoaClass alloc] init];
> 	}
>
> Another way is to do the initialization in a class's +initialize method.
>
> —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: 
 >Global Object (From: Tom Jones <email@hidden>)
 >Re: Global Object (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: Apache Module
  • Next by Date: Re: Apache Module
  • Previous by thread: Re: Global Object
  • Next by thread: Custom Controls Where to start
  • Index(es):
    • Date
    • Thread