ZGSynthesizeSingleton.h 880 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // MySynthesizeSingleton.h
  3. // DDZFrame
  4. //
  5. // Created by song on 10-8-19.
  6. // Copyright 2010 __MyCompanyName__. All rights reserved.
  7. //
  8. #define ZG_SYNTHESIZE_SINGLETON_FOR_CLASS(classname) \
  9. \
  10. static classname *shared##classname = nil; \
  11. \
  12. + (classname *)shared \
  13. { \
  14. @synchronized(self) \
  15. { \
  16. if (shared##classname == nil) \
  17. { \
  18. shared##classname = [[self alloc] init]; \
  19. } \
  20. } \
  21. \
  22. return shared##classname; \
  23. } \
  24. /*
  25. \
  26. + (id)allocWithZone:(NSZone *)zone \
  27. { \
  28. @synchronized(self) \
  29. { \
  30. if (shared##classname == nil) \
  31. { \
  32. shared##classname = [super allocWithZone:zone]; \
  33. return shared##classname; \
  34. } \
  35. } \
  36. \
  37. return nil; \
  38. } \
  39. \
  40. - (id)copyWithZone:(NSZone *)zone \
  41. { \
  42. return self; \
  43. } \
  44. \
  45. - (id)retain \
  46. { \
  47. return self; \
  48. } \
  49. \
  50. - (NSUInteger)retainCount \
  51. { \
  52. return NSUIntegerMax; \
  53. } \
  54. \
  55. - (oneway void)release \
  56. { \
  57. } \
  58. \
  59. - (id)autorelease \
  60. { \
  61. return self; \
  62. }
  63. */