BOOL didAddMethod = class_addMethod(class, origSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod)); if (didAddMethod) { class_WordStrMethod(class, newSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod)); } else { method_exchangeImplementations(originalMethod, swizzledMethod); } } + (void)load { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ id obj = [[self alloc] init]; [obj swizzleMethod:@selector(setObject:forKey:) withMethod:@selector(safe_setObject:forKey:)]; }); } - (void)safe_setObject:(id)value forKey:(NSString *)key { if (value) { [self safe_setObject:value forKey:key]; }else { NullSafeLogFormatter(@"[NSMutableDictionary setObject: forKey:], Object cannot be nil") } } @end 这种解决办法可以避免诸如数组取值袈浣界、字典传空值、removeObjectAtIndex等缺点,如下的崩溃就可以避免:
- id obj = nil;
- NSMutableDictionary *m_dict = [NSMutableDictionary dictionary];
- [dict setObject:obj forKey:@"666"];
2.2 监控体系
今朝大年夜多半App都集成了第三方统计库,常见的比如腾讯的Bugly、友盟的U-App等等,在这介绍下若何自建机能监控库
推荐阅读
从交通三元素看高德易行新平台
“高德易行平台的上线,标记住高德地图在交通出行计谋进级上迈出了重要一步。其实交通在我看来竽暌剐三元素,就是人、车和路,它们构成了交通核心的关键词。将来高德将以易行平台与交>>>详细阅读
本文标题:iOS如何进行优化项目?
地址:http://www.17bianji.com/lsqh/36461.html
1/2 1