사용자가 init을 호출하지 않도록하려면 어떻게해야합니까? 대신 클라이언트가 sharedSingleton을 호출하여 공유 인스턴스를 가져와야합니다.objc의 싱글 톤 패턴, init을 비공개로 유지하는 방법?
@synthesize delegate;
- (id)init
{
self = [super init];
if (self) {
// Initialization code here.
}
return self;
}
+ (LoginController *)sharedSingleton
{
static LoginController *sharedSingleton;
@synchronized(self)
{
if (!sharedSingleton)
sharedSingleton = [[LoginController alloc] init];
CdtMiscRegisterConnectionChangeListenerObjc(test_ConnectionChangeListenerCallback);
return sharedSingleton;
}
}
그들은, 비록 확장 (AKA "빈 카테고리")을 에뮬레이트 할 수 있습니다 구현한다. –