Re: ARC and Singletons

2011-08-05 Thread Robert Monaghan
Submitted as an enhancement request.. :) Bug ID# 9908437 bob.. On Aug 2, 2011, at 5:29 PM, Dave Zarzycki wrote: > Karl, > > This is not on our todo list or any list that I know of. Please file a bug > report if this enhancement request is interesting to you. > > Thanks! :-) > > davez > >

Re: ARC and Singletons

2011-08-03 Thread Andreas Grosam
On Aug 3, 2011, at 2:29 AM, Dave Zarzycki wrote: > Karl, > > This is not on our todo list or any list that I know of. Please file a bug > report if this enhancement request is interesting to you. > > Thanks! :-) Oh, we need to file an enhancement request when we would like to have class vari

Re: ARC and Singletons

2011-08-02 Thread Dave Zarzycki
Karl, This is not on our todo list or any list that I know of. Please file a bug report if this enhancement request is interesting to you. Thanks! :-) davez On Aug 2, 2011, at 4:59 PM, Karl Goiser wrote: > Hi Greg, > > Is that wishful thinking or a hint about the future? > :-) > > > All I

Re: ARC and Singletons

2011-08-02 Thread Karl Goiser
Hi Greg, Is that wishful thinking or a hint about the future? :-) All I have to say is: yes please!! Regards, Karl On 03/08/2011, at 5:43 AM, Greg Parker wrote: > On Aug 1, 2011, at 9:02 PM, Kyle Sluder wrote: >> if we had class storage (which in practice would be no different from >> stat

Re: ARC and Singletons

2011-08-02 Thread Greg Parker
On Aug 1, 2011, at 9:02 PM, Kyle Sluder wrote: > if we had class storage (which in practice would be no different from > static global variables except for scope), class methods would still > be appropriate for a different set of tasks. Not necessarily. Class variables could be defined differently

Re: ARC and Singletons

2011-08-02 Thread Jean-Daniel Dupas
Le 2 août 2011 à 08:22, Karl Goiser a écrit : > Yes they are. > > > They are a kludge that came about because C++ doesn’t implement object > behaviour properly. > > Try this: http://www.google.com/search?hl=en&q=Singleton%2Bevil > > > You have not said what about NSFileManager is a great ex

Re: ARC and Singletons

2011-08-01 Thread Karl Goiser
Yes they are. They are a kludge that came about because C++ doesn’t implement object behaviour properly. Try this: http://www.google.com/search?hl=en&q=Singleton%2Bevil You have not said what about NSFileManager is a great example of the singleton pattern. Of course class methods have thei

Re: ARC and Singletons

2011-08-01 Thread Kyle Sluder
On Mon, Aug 1, 2011 at 7:14 PM, Karl Goiser wrote: > Wow, class methods finally get the tick of approval!  Only 30+ years after > being specified in the Smalltalk standard.. > > > Forget about singletons: they are just a workaround for not having class > methods/variables. No, they're not. I me

Re: ARC and Singletons

2011-08-01 Thread Karl Goiser
Wow, class methods finally get the tick of approval! Only 30+ years after being specified in the Smalltalk standard.. Forget about singletons: they are just a workaround for not having class methods/variables. Each class is a single object that exists for the life of the application therefo

Re: ARC and Singletons

2011-08-01 Thread Jeff Kelley
Traditionally, I used the standard +sharedInstance type of singleton, but I returned it autoreleased and in its dealloc method, set the sharedInstance variable to nil if it was the shared instance: > - (void)dealloc > { > if (self == sharedInstance) { > sharedInstance = nil; > }

Re: ARC and Singletons

2011-08-01 Thread David Duncan
On Aug 1, 2011, at 10:12 AM, Kyle Sluder wrote: > On Mon, Aug 1, 2011 at 9:05 AM, Dave Zarzycki wrote: >> The simplest and most ARC friendly way to implement the singleton pattern is >> to switch from instance methods to class methods – because the class itself >> is by definition a singleton.

Re: ARC and Singletons

2011-08-01 Thread Kyle Sluder
On Mon, Aug 1, 2011 at 10:12 AM, Kyle Sluder wrote: > if it's necessary to store the shared instance in an ivar, why not do > the following: Wow, I need coffee. ivars vs class variables… Wow. Forget that second example. That's just terrible. Imagine, instead, I used whatever storage mechanism

Re: ARC and Singletons

2011-08-01 Thread Kyle Sluder
On Mon, Aug 1, 2011 at 9:05 AM, Dave Zarzycki wrote: > The simplest and most ARC friendly way to implement the singleton pattern is > to switch from instance methods to class methods – because the class itself > is by definition a singleton. In other words: Eek, this might be conceptually simpl

Re: ARC and Singletons

2011-08-01 Thread Dave Zarzycki
On Aug 1, 2011, at 9:08 AM, Jeff Kelley wrote: > Interesting. Your +setFoo: example, I’m assuming, sets a global int. Correct. > What about objects? I’m assuming that if I declare a global NSArray pointer > like so: > > NSArray *foo = nil; In general, globals default initialize to zero/nil/N

Re: ARC and Singletons

2011-08-01 Thread Dave DeLong
That would work. However, you lose out on being able to declare "foo" as an @property (not a big deal) and have to write the accessors yourself (annoying, since the compiler knows how to do this already but can't in this case). Dave On Aug 1, 2011, at 9:05 AM, Dave Zarzycki wrote: > The simpl

Re: ARC and Singletons

2011-08-01 Thread Jeff Kelley
Interesting. Your +setFoo: example, I’m assuming, sets a global int. What about objects? I’m assuming that if I declare a global NSArray pointer like so: NSArray *foo = nil; and then have a +setFoo:(NSArray *)array method, that calling it with nil will be sufficient to clean up the array (that is

Re: ARC and Singletons

2011-08-01 Thread Dave Zarzycki
The simplest and most ARC friendly way to implement the singleton pattern is to switch from instance methods to class methods – because the class itself is by definition a singleton. In other words: + (MyClass *)sharedInstance; // and maybe override alloc/retain/release to enforc

Re: ARC and Singletons

2011-08-01 Thread Thomas Davie
On 1 Aug 2011, at 16:48, Jeff Kelley wrote: > Is there a new recommended way to implement a singleton with ARC? I remember > hearing something about it, but I’m not sure what it was. Was it perhaps… don't use singletons, they're just globals in disguise? Bob_

ARC and Singletons

2011-08-01 Thread Jeff Kelley
Is there a new recommended way to implement a singleton with ARC? I remember hearing something about it, but I’m not sure what it was. Jeff Kelley ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator com