Skip to content

Instantly share code, notes, and snippets.

@hisasann hisasann/singleton.m
Created Jul 30, 2012

Embed
What would you like to do?
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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.