반응형


// h
@interface MyClass : NSObject {

}
+ (MyClass *)sharedClass;
- (void)run;

// m
#import "MyClass.h"
static MyClass *sharedMyClass = nil;

@implementation MyClass
+ (MyClass *)sharedClass {
    @synchronized(self) {
        if (nil == sharedMyClass) {
            sharedMyClass = [[MyClass alloc] init];
        }
    }

    return sharedMyClass;
}
- (void)run {
    NSLog(@"run");
}

@end

// 사용방법
[[MyClass sharedClass] run];


반응형
Posted by 컴스터
,