NSDictionary-NilSafe icon indicating copy to clipboard operation
NSDictionary-NilSafe copied to clipboard

建议

Open caixindong opened this issue 8 years ago • 0 comments

将方法交换那一块改为以下这样子,原有的实现在系统API使用到NSNull的时候会crash,因为按原有方法在做NSNull swizzle的时候会添加方法失败,消息转发的相关函数是没有默认实现的 Method originMth = class_getInstanceMethod(self, originSel); Method altMth = class_getInstanceMethod(self, altSel); if (!originMth || !altMth) { return NO; } BOOL success = class_addMethod(self, originSel, method_getImplementation(altMth), method_getTypeEncoding(altMth)); if (success) { class_replaceMethod(self, altSel, method_getImplementation(originMth), method_getTypeEncoding(originMth)); }else { method_exchangeImplementations(originMth, altMth); } return YES;

caixindong avatar Jan 13 '17 09:01 caixindong