+ (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];
}
「UITableView + Swizzling」に入れたとき。 iPad Proを選択します。それはクラッシュするでしょう。Xcode8 + ipad。メソッドSwizzling UITableView backgroundColorクラッシュ
クラッシュログは次のとおりです。アサーションエラーvoid PushNextClassForSettingIMP(id、SEL())。アプリを終了 キャッチされない例外により 'にNSInternalInconsistencyException' が
.....なぜiPad用