Skip to content

Instantly share code, notes, and snippets.

@annidy
Created September 20, 2020 07:19
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 annidy/4ee159680aefd4178bf907cb82279aaa to your computer and use it in GitHub Desktop.
Save annidy/4ee159680aefd4178bf907cb82279aaa to your computer and use it in GitHub Desktop.
disalbe NSAssert
#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