Objective-C單例模式的實現

#define IMPLEMENT_SINGLETON(cls_name, method_name)\
    + (cls_name *)method_name {\
        static cls_name *method_name;\
        static dispatch_once_t onceToken;\
        dispatch_once(&onceToken, ^{\
            method_name = [[cls_name alloc] init];\
        });\
        return method_name;\

    } spa

IMPLEMENT_SINGLETON(NSClass, sharedObject) it

相關文章
相關標籤/搜索