Singleton on iOS (obj-C achieves Singleton mode)
Reference: http://www.duckrowing.com/2010/05/21/using-the-singleton-pattern-in-objective-c/
Static Mygizmoclass * Sharedgizmomanager = Nil;
+(Mygizmoclass*) Sharedmanager
{
@ Synchronized (Self ){
If(Sharedgizmomanager=Nil ){
[[Self alloc] init];//Assignment not done here
}
}
ReturnSharedgizmomanager;
}
+ (ID) allocwithzone :( nszone * ) Zone
{
@ Synchronized (Self ){
If (Sharedgizmomanager = Nil ){
Sharedgizmomanager = [Super allocwithzone: Zone];
Return Sharedgizmomanager; // Assignment and return on first allocation
}
}
Return Nil; // On subsequent allocation attempts return Nil
}
-(ID) copywithzone :( nszone*) Zone
{
ReturnSelf;
}
-(ID) Retain
{
ReturnSelf;
}
-(Unsigned) retaincount
{
ReturnUint_max;//Denotes an object that cannot be released
}
-(Void) Release
{
//Do nothing
}
- (ID) autorelease
{< br> return self;
}