Skip to content

Instantly share code, notes, and snippets.

@hisasann
Created July 30, 2012 04:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hisasann/3204441 to your computer and use it in GitHub Desktop.
Save hisasann/3204441 to your computer and use it in GitHub Desktop.
Objective-Cでシングルトン
#import "Status.h"
@implementation Status
@synthesize customUrlAlbumId = _customUrlAlbumId;
@synthesize isTopReload = _isTopReload;
@synthesize isThumbnailReload = _isThumbnailReload;
@synthesize isInvitationReload = _isInvitationReload;
static Status *sharedHistory = nil;
+ (Status *)sharedManager {
@synchronized (self) {
if (sharedHistory == nil) {
sharedHistory = [[self alloc] init];
}
}
return sharedHistory;
}
+ (id)allocWithZone:(NSZone *)zone {
@synchronized (self) {
if (sharedHistory == nil) {
sharedHistory = (Status *) [super allocWithZone:zone];
return sharedHistory;
}
}
return nil;
}
- (id)copyWithZone:(NSZone *)zone {
return self; // シングルトン状態を保持するため何もせず self を返す
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment