Singleton.h 406 B

12345678910111213141516
  1. //单例
  2. #define DECLARE_SINGLETON(CLASS_NAME) \
  3. + (CLASS_NAME *)sharedInstance;
  4. #define SYNTHESIZE_SINGLETONE_FOR_CLASS(CLASS_NAME) \
  5. + (CLASS_NAME *)sharedInstance\
  6. {\
  7. static CLASS_NAME *__##CLASS_NAME##_instance = nil;\
  8. \
  9. static dispatch_once_t onceToken;\
  10. dispatch_once(&onceToken, ^{\
  11. __##CLASS_NAME##_instance = [[CLASS_NAME alloc] init];\
  12. });\
  13. return __##CLASS_NAME##_instance;\
  14. }