Skip to content

Instantly share code, notes, and snippets.

@metasmile
Created August 20, 2015 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metasmile/cf88df9207d3ba9e8830 to your computer and use it in GitHub Desktop.
Save metasmile/cf88df9207d3ba9e8830 to your computer and use it in GitHub Desktop.
dealloc in category
#define BEGIN_DEALLOC_CATEGORY + (void)load {\
SEL originalSelector = NSSelectorFromString(@"dealloc");\
SEL overrideSelector = @selector(__dealloc__);\
Method originalMethod = class_getInstanceMethod(self, originalSelector);\
Method overrideMethod = class_getInstanceMethod(self, overrideSelector);\
if (class_addMethod(self, originalSelector, method_getImplementation(overrideMethod), method_getTypeEncoding(overrideMethod))) {\
class_replaceMethod(self, overrideSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));\
} else {\
method_exchangeImplementations(originalMethod, overrideMethod);\
}\
}\
\
- (void)__dealloc__{\
#define END_DEALLOC_CATEGORY }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment