博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS开发NSMutableArray数组越界处理
阅读量:6324 次
发布时间:2019-06-22

本文共 2590 字,大约阅读时间需要 8 分钟。

#import "NSArray+CrashArray.h"#import 
@implementation NSObject (Until)- (void)swizzleMethod:(SEL)originalSelector swizzledSelector:(SEL)swizzledSelector{ Class class = [self class]; Method original = class_getInstanceMethod(class, originalSelector); Method Swizzl = class_getInstanceMethod(class, swizzledSelector); BOOL didAdd = class_addMethod(class, originalSelector, method_getImplementation(Swizzl), method_getTypeEncoding(Swizzl)); if (didAdd) { class_replaceMethod(class, swizzledSelector, method_getImplementation(original), method_getTypeEncoding(original)); }else{ method_exchangeImplementations(original, Swizzl); }}@end@implementation NSArray (CrashArray)- (id)safeObjectAtIndex:(NSUInteger)index{ if (index
count %lu",(unsigned long)index,(unsigned long)self.count);//#endif return nil; }}- (id)safeObjectAtIndex1:(NSUInteger)index{ if (index
count %lu",(unsigned long)index,(unsigned long)self.count);//#endif return nil; }}- (id)safeObjectAtIndex2:(NSUInteger)index{ if (index
count %lu",(unsigned long)index,(unsigned long)self.count);//#endif return nil; }}- (id)safeObjectAtIndex3:(NSUInteger)index{ if (index
count %lu",(unsigned long)index,(unsigned long)self.count);//#endif return nil; }}+ (void)load{ static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ @autoreleasepool { [objc_getClass("__NSArrayI") swizzleMethod:@selector(objectAtIndex:) swizzledSelector:@selector(safeObjectAtIndex:)]; [objc_getClass("__NSArrayI") swizzleMethod:@selector(objectAtIndexedSubscript:) swizzledSelector:@selector(safeObjectAtIndex1:)]; [objc_getClass("__NSArrayM") swizzleMethod:@selector(objectAtIndex:) swizzledSelector:@selector(safeObjectAtIndex2:)]; [objc_getClass("__NSArrayM") swizzleMethod:@selector(objectAtIndexedSubscript:) swizzledSelector:@selector(safeObjectAtIndex3:)]; } });}@end@implementation NSDictionary(DictinaryCrash)- (void)mutableSetObject:(id)obj forKey:(NSString *)key{ if (obj && key) { [self mutableSetObject:obj forKey:key]; }}+ (void)load{ static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ @autoreleasepool{ [objc_getClass("__NSDictionaryM") swizzleMethod:@selector(setObject:forKey:) swizzledSelector:@selector(mutableSetObject:forKey:)]; } });}@end

 

转载于:https://www.cnblogs.com/xianfeng-zhang/p/9341325.html

你可能感兴趣的文章
[LeetCode] Combine Two Tables 联合两表
查看>>
vc维的解释
查看>>
产品需求文档(PRD)的写作方法之笔记一
查看>>
[android] WebView与Js交互
查看>>
C++ new的nothrow关键字和new_handler用法
查看>>
java lambda表达式学习笔记
查看>>
Linux挂载命令mount用法及参数详解
查看>>
只有文本编辑器才是王道, 什么ide都是evil的浮云, 看看linus linux的内核开发工具vim emacs...
查看>>
HtmlAgilityPack使用
查看>>
详解 Spotlight on MySQL监控MySQL服务器
查看>>
修改MySQL自动递增值
查看>>
2016年8月编程语言排行榜
查看>>
使用Nginx负载均衡搭建高性能.NETweb应用程序一
查看>>
vs vim 插件
查看>>
leetcode409
查看>>
thinkphp并发 阻塞模式与非阻塞模式
查看>>
SQL SERVER 2005 进行XML查询
查看>>
oracle存储过程
查看>>
2013年省赛总结
查看>>
为Apple Push开发的PHP PEAR 包:Services_Apple_PushNotification
查看>>