跳到主要內容

發表文章

目前顯示的是 8月, 2017的文章

[AWS] update SNS credentials

  官方說明︰ http://docs.aws.amazon.com/zh_cn/sns/latest/dg/mobile-push-apns.html 但要上傳的是這個p12  

[iOS] Singleton pattern in objc, how to keep init private?

From https://stackoverflow.com/questions/7034971/singleton-pattern-in-objc-how-to-keep-init-private Throw an exception in init - (instancetype)init { [self doesNotRecognizeSelector:_cmd]; return nil; } - (instancetype)initPrivate { self = [super init]; if (self) { } return self; } + (instancetype)sharedInstance { static MySingleton *sharedInstance; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ sharedInstance = [[self alloc] initPrivate]; }); return sharedInstance; } Have init return your singleton - (instancetype)init { return [[self class] sharedInstance]; } - (instancetype)initPrivate { self = [super init]; if (self) { } return self; } + (instancetype)sharedInstance { static MySingleton2 *sharedInstance; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ sharedInstance = [[self alloc] initPrivate]; }); return sharedInstance; }