Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
9
Task/Singleton/Objective-C/singleton-1.m
Normal file
9
Task/Singleton/Objective-C/singleton-1.m
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
// SomeSingleton.h
|
||||
@interface SomeSingleton : NSObject
|
||||
{
|
||||
// any instance variables
|
||||
}
|
||||
|
||||
+ (SomeSingleton *)sharedInstance;
|
||||
|
||||
@end
|
||||
38
Task/Singleton/Objective-C/singleton-2.m
Normal file
38
Task/Singleton/Objective-C/singleton-2.m
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
// SomeSingleton.m
|
||||
@implementation SomeSingleton
|
||||
|
||||
+ (SomeSingleton *) sharedInstance
|
||||
{
|
||||
static SomeSingleton *sharedInstance = nil;
|
||||
if (!sharedInstance) {
|
||||
sharedInstance = [[SomeSingleton alloc] init];
|
||||
}
|
||||
return sharedInstance;
|
||||
}
|
||||
|
||||
- (id)copyWithZone:(NSZone *)zone
|
||||
{
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)retain
|
||||
{
|
||||
return self;
|
||||
}
|
||||
|
||||
- (unsigned)retainCount
|
||||
{
|
||||
return UINT_MAX;
|
||||
}
|
||||
|
||||
- (oneway void)release
|
||||
{
|
||||
// prevent release
|
||||
}
|
||||
|
||||
- (id)autorelease
|
||||
{
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
10
Task/Singleton/Objective-C/singleton-3.m
Normal file
10
Task/Singleton/Objective-C/singleton-3.m
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
+ (SomeSingleton *) sharedInstance
|
||||
{
|
||||
static SomeSingleton *sharedInstance = nil;
|
||||
@synchronized(self) {
|
||||
if (!sharedInstance) {
|
||||
sharedInstance = [[SomeSingleton alloc] init];
|
||||
}
|
||||
}
|
||||
return sharedInstance;
|
||||
}
|
||||
9
Task/Singleton/Objective-C/singleton-4.m
Normal file
9
Task/Singleton/Objective-C/singleton-4.m
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
+ (SomeSingleton *) sharedInstance
|
||||
{
|
||||
static SomeSingleton *sharedInstance = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
sharedInstance = [[SomeSingleton alloc] init];
|
||||
});
|
||||
return sharedInstance;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue