Flores Robles
Flores Robles

Reputation: 656

should a singleton use self or shared instance inside the methods

inside the singleton methods how should I use a singleton:

like:

     [self doMethod];

or:

    [[SingletonClass sharedSingleton] doMethod];

?

Upvotes: 3

Views: 608

Answers (2)

Chuck
Chuck

Reputation: 237110

I can think of no reason to do it the second way. That way is longer, slower and more brittle -- and there's no upside to it. Just use self unless you have a really compelling reason to do otherwise. Singletons are essentially just normal objects.

Upvotes: 7

Chris Gerken
Chris Gerken

Reputation: 16400

I prefer to minimize the number of calls made by the client, so I recommend you have a convenience class method on your singleton that sends the instance method to the singleton.

Upvotes: 1

Related Questions