Create a gist now

Instantly share code, notes, and snippets.

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