Created
September 20, 2020 07:19
-
-
Save annidy/4ee159680aefd4178bf907cb82279aaa to your computer and use it in GitHub Desktop.
disalbe NSAssert
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
#import <objc/runtime.h> | |
@implementation NSAssertionHandler (Disable) | |
+ (void)initialize { | |
[self swizzMethod:@selector(handleFailureInMethod:object:file:lineNumber:description:) to:@selector(swizz_handleFailureInMethod:object:file:lineNumber:description:)]; | |
[self swizzMethod:@selector(handleFailureInFunction:file:lineNumber:description:) to:@selector(swizz_handleFailureInFunction:file:lineNumber:description:)]; | |
} | |
+ (void)swizzMethod:(SEL)originalSelector to:(SEL)swizzledSelector { | |
Method originalMethod = class_getInstanceMethod(self, originalSelector); | |
Method swizzledMethod = class_getInstanceMethod(self, swizzledSelector); | |
BOOL didAddMethod = | |
class_addMethod(self.class, | |
originalSelector, | |
method_getImplementation(swizzledMethod), | |
method_getTypeEncoding(swizzledMethod)); | |
if (didAddMethod) { | |
class_replaceMethod(self, | |
swizzledSelector, | |
method_getImplementation(originalMethod), | |
method_getTypeEncoding(originalMethod)); | |
} else { | |
method_exchangeImplementations(originalMethod, swizzledMethod); | |
} | |
} | |
- (void)swizz_handleFailureInMethod:(SEL)selector object:(id)object file:(NSString *)fileName lineNumber:(NSInteger)line description:(nullable NSString *)format,... NS_FORMAT_FUNCTION(5,6); | |
{ | |
} | |
- (void)swizz_handleFailureInFunction:(NSString *)functionName file:(NSString *)fileName lineNumber:(NSInteger)line description:(nullable NSString *)format,... NS_FORMAT_FUNCTION(4,5); | |
{ | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment