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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to