0
+ (void)load {
    [super load];
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        Class aClass = [self class];
        SEL selector = @selector(setBackgroundColor:);
        SEL _selector = @selector(cusSetBackgroundColor:);

        Method method = class_getInstanceMethod(aClass, selector);
        Method _method = class_getInstanceMethod(aClass, _selector);

        BOOL did = class_addMethod(aClass, selector, method_getImplementation(_method), method_getTypeEncoding(_method));
        if (did) {
            class_replaceMethod(aClass, _selector, method_getImplementation(method), method_getTypeEncoding(method));
        } else {
            class_addMethod(aClass, _selector, method_getImplementation(_method), method_getTypeEncoding(_method));
            method_exchangeImplementations(method, _method);
        }
    });
}
- (void)cusSetBackgroundColor:(UIColor *)backgroundColor
{
    NSLog(@"test swizzling");
    [self cusSetBackgroundColor:backgroundColor];
}

when i put it into "UITableView+Swizzling". And choose iPad Pro. it will crash. (iPhone runs well)

the crash log is: Assertion failure in void PushNextClassForSettingIMP(id, SEL()). Terminating app due to uncaught exception 'NSInternalInconsistencyException'

don't konw why.....

2 Answers2

0

for ipad. i run 'p class_getInstanceMethod(aClass, @selector(setBackgroundColor:))' the console can't output the function address. but for iPhone. i can get the address.

so i tried 'p class_getInstanceMethod(aClass, @selector(_setBackgroundColor))'

problem solved..

but it's just so strange. if you konw other soluetion. please let me konw.

0

The same crash with me, and I resolved it use UIView instead of UITableView.