Re: class keeps track of object

2008-07-01 Thread Shripada Hebbar
Daniel You are trying to create a singleton object in cocoa and there is a good documentation on this at: http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/chapter_3_section_10.html -Shripada > > Thanks! Exactly what I was looking for. > > Daniel > > >

Re: class keeps track of object

2008-07-01 Thread Sherm Pendley
On Tue, Jul 1, 2008 at 6:49 PM, Jonathan Hess <[EMAIL PROTECTED]> wrote: > Han Daniel - > > You can use a global variable just like you would in C: Yes, but... > static Foo *bar = nil; That's not a global. Static vars are file scoped. :-) In Foo.m: Foo *globalFoo = nil; In Foo.h, somewher

Re: class keeps track of object [solved]

2008-07-01 Thread Daniel Richman
Thanks! Exactly what I was looking for. Daniel Jonathan Hess wrote: Han Daniel - You can use a global variable just like you would in C: static Foo *bar = nil; @implementation Foo + (id)bar { if (!bar) { bar = [[Foo alloc] init]; } return bar;

Re: class keeps track of object

2008-07-01 Thread Jonathan Hess
Han Daniel - You can use a global variable just like you would in C: static Foo *bar = nil; @implementation Foo + (id)bar { if (!bar) { bar = [[Foo alloc] init]; } return bar; } @end Thats the simple single threaded case. Things get much more interesting if you want to be

Re: class keeps track of object

2008-07-01 Thread Jean-Daniel Dupas
search for singleton pattern (in the archives and in Apple doc too). The simplest way to do it is (not thread safe): @implementation Foo + (Bar *)sharedFoo { static Foo *shardInstance = nil; if (!sharedInstance) sharedInstance = [[Foo alloc] init]; return sharedInstance; } @end Le 2

class keeps track of object

2008-07-01 Thread Daniel Richman
Hi All, I have created a class (call it Foo) that there will be one and only one instance of (call it Bar). I need some way to have Foo keep a pointer to Bar, so when another object asks for the pointer to Bar, Foo will be able to return the pointer. Presumably this can be done, as NSNotific