Re: singleton design pattern
Re: singleton design pattern
- Subject: Re: singleton design pattern
- From: Alejandro Marcos Aragón <email@hidden>
- Date: Wed, 19 May 2010 18:39:44 -0500
Static variables inside member functions are initialized only once, static variables therefore keep the state of the variable in repeated calls.
aa
On May 19, 2010, at 6:37 PM, Graham Cox wrote:
>
> On 20/05/2010, at 7:35 AM, Abhinay Kartik Reddyreddy wrote:
>
>> everytime you ask for a uniqueInstance it looks like it retrieves a new instance not the existing instance... since you set the uniqueinstance to nil inside that function, your function will discard the previous instance if any and then create a new instance. Singleton is supposed to return existing instance if any and if none create one.
>>
>> Also i guess the scope of your static is local.
>>
>> correct me if i am wrong.
>
>
> OK then I will.
>
> static NSObject* something = nil;
>
> does not repeatedly set the variable 'something' to nil every time the method is entered. It sets it once when the app starts. Once the variable is assigned, it stays assigned. Check up on what 'static' means, don't guess and give advice based on that incorrect guess.
>
> --Graham
>
>
_______________________________________________
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