Skip to content

Instantly share code, notes, and snippets.

@mhupman
Last active December 15, 2015 02:29
Show Gist options
  • Save mhupman/5187317 to your computer and use it in GitHub Desktop.
Save mhupman/5187317 to your computer and use it in GitHub Desktop.
NSObject+JRSwizzleBlock.[h,m]
/* NSObject+JRSwizzleBlock.h */
#import <Foundation/Foundation.h>
@interface NSObject(JRSwizzleBlock)
+ (void)swizzle:(SEL)origmethod toMethod:(SEL)newmethod forBlock:(void(^)(void))swizzledBlock;
@end
/* NSObject+JRSwizzleBlock.m */
#import "NSObject+JRSwizzleBlock.h"
#import <JRSwizzle.h>
@implementation NSObject(JRSwizzleBlock)
+ (void)swizzle:(SEL)origmethod toMethod:(SEL)newmethod forBlock:(void(^)(void))swizzledBlock
{
if (!swizzledBlock)
return;
@try
{
[self jr_swizzleMethod:origmethod withMethod:newmethod error:nil];
swizzledBlock();
}
@finally
{
[self jr_swizzleMethod:newmethod withMethod:origmethod error:nil];
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment