싱글톤
싱글톤은 SharedInstance
라는 명목으로 코코아 내에서도 상당히 자주 쓰이는 패턴이다. SharedApplication이나 NSFileManager, NSNotificationCenter 등에서 많이 활용된다. 쉽게 생각하면 다음과 같은 식으로 구현하면 될 것이라 보는데…
static SomeClass *sharedObject;
+ (SomeClass *)sharedInstance {
if (sharedObject == nil) {
sharedObject = [[self alloc] init];
}
return sharedObject;
}