Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#define KZRMETHOD_SWIZZLING_WITHBLOCK(className, selectorName, isClassMethod, originalIMP, originalSelector, block) {\
BOOL _val_isClassMethod=isClassMethod; \
const char* _val_selName=selectorName; \
if(*_val_selName=='+'){_val_isClassMethod=YES; _val_selName++;} \
Class _val_cls=objc_getClass(className); \
SEL originalSelector=sel_registerName(_val_selName); \
Method _val_originalMethod; \
if (_val_isClassMethod)_val_originalMethod = class_getClassMethod(_val_cls, originalSelector); \
else _val_originalMethod = class_getInstanceMethod(_val_cls, originalSelector); \
KZRIMPUnion originalIMP = (KZRIMPUnion)(IMP)method_getImplementation(_val_originalMethod); \
if (originalIMP.as_id) { id _val_block=block \
;IMP _val_newImp = imp_implementationWithBlock(_val_block); \
method_setImplementation(_val_originalMethod, _val_newImp); \
} \
KZRInstanceMethod, originalIMP, originalSelector,
^NSRect (id rself){ // SEL is not brought (id self, arg1, arg2...)
NSRect result=originalIMP.as_rect(rself, originalSelector);
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSLog(@"frame=%@", NSStringFromRect(result));
return result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.