Skip to main content
added 1 characters in body
Source Link
i_am_jorf
  • 54.8k
  • 15
  • 136
  • 225

I've not read through all the solutions, so forgive if this code is redundant.

This is the most treadthread safe implementation in my opinion.

+(SingletonObject *) sharedManager { static SingletonObject * sharedResourcesObj = nil; @synchronized(self) { if (!sharedResourcesObj) { sharedResourcesObj = [[SingletonObject alloc] init]; } } return sharedResourcesObj; } 

I've not read through all the solutions, so forgive if this code is redundant.

This is the most tread safe implementation in my opinion.

+(SingletonObject *) sharedManager { static SingletonObject * sharedResourcesObj = nil; @synchronized(self) { if (!sharedResourcesObj) { sharedResourcesObj = [[SingletonObject alloc] init]; } } return sharedResourcesObj; } 

I've not read through all the solutions, so forgive if this code is redundant.

This is the most thread safe implementation in my opinion.

+(SingletonObject *) sharedManager { static SingletonObject * sharedResourcesObj = nil; @synchronized(self) { if (!sharedResourcesObj) { sharedResourcesObj = [[SingletonObject alloc] init]; } } return sharedResourcesObj; } 
Source Link
Zolt
  • 2.8k
  • 9
  • 47
  • 64

I've not read through all the solutions, so forgive if this code is redundant.

This is the most tread safe implementation in my opinion.

+(SingletonObject *) sharedManager { static SingletonObject * sharedResourcesObj = nil; @synchronized(self) { if (!sharedResourcesObj) { sharedResourcesObj = [[SingletonObject alloc] init]; } } return sharedResourcesObj; }