CWSington.h 610 B

12345678910111213141516171819202122232425262728293031323334
  1. //
  2. // Sington.h
  3. // CWAudioTool
  4. //
  5. // Created by chavez on 2017/9/26.
  6. // Copyright © 2017年 chavez. All rights reserved.
  7. //
  8. #define singtonInterface + (instancetype)shareInstance;
  9. #define singtonImplement(class) \
  10. \
  11. static class *_shareInstance; \
  12. \
  13. + (instancetype)shareInstance { \
  14. \
  15. if(_shareInstance == nil) {\
  16. _shareInstance = [[class alloc] init]; \
  17. } \
  18. return _shareInstance; \
  19. } \
  20. \
  21. +(instancetype)allocWithZone:(struct _NSZone *)zone { \
  22. \
  23. static dispatch_once_t onceToken; \
  24. dispatch_once(&onceToken, ^{ \
  25. _shareInstance = [super allocWithZone:zone]; \
  26. }); \
  27. \
  28. return _shareInstance; \
  29. \
  30. }