Interesting/objective - C

singleton source snnipet

닉네임영역 2013. 10. 15. 09:46

* 이렇게 싱글톤으로 안하고 직접 Prefix.pch에 바로 전역 선언으로 만들어 쓰는 방법도 있습니다. 


이제 선언했으니 함수에서 사용합니다.

@implementation Object

static Object *__sharedObject;

+ (Object *)sharedObject {

        if (__sharedObject == nil) {

                __sharedObject = [[Object alloc] init];

        }

        return __sharedObject;

}

@end