Last active
December 15, 2015 02:29
-
-
Save mhupman/5187317 to your computer and use it in GitHub Desktop.
NSObject+JRSwizzleBlock.[h,m]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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