Created
May 7, 2013 15:04
-
-
Save gin0606/5533319 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static __ClassName__ *shared__ClassName__ = nil; | |
+ (__ClassName__ *)shared__ClassName__ { | |
@synchronized (self) { | |
if (shared__ClassName__ == nil) { | |
[[[self alloc] init] autorelease]; // ここでは代入していない | |
} | |
} | |
return shared__ClassName__; | |
} | |
+ (id)allocWithZone:(NSZone *)zone { | |
@synchronized (self) { | |
if (shared__ClassName__ == nil) { | |
shared__ClassName__ = (__ClassName__ *) [super allocWithZone:zone]; | |
return shared__ClassName__; // 最初の割り当てで代入し、返す | |
} | |
} | |
return nil; // 以降の割り当てではnilを返すようにする | |
} | |
- (id)copyWithZone:(NSZone *)zone { | |
return self; | |
} | |
- (id)retain { | |
return self; | |
} | |
- (unsigned)retainCount { | |
return UINT_MAX; // 解放できないオブジェクトであることを示す | |
} | |
-(oneway void)release{ | |
// 何もしない | |
} | |
- (id)autorelease { | |
return self; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment