分类使用runtime交换方法
来源:互联网 发布:九寨沟地震网络谣言 编辑:程序博客网 时间:2024/05/18 03:02
#import "NSArray+Safe.h"
#import <objc/runtime.h>
@implementation NSArray (Safe)
//程序启动就会调用的方法
+ (void)load {
Class class = NSClassFromString(@"__NSArrayI");
SEL system =@selector(objectAtIndex:);
SEL custom =@selector(safeobjectAtIndex:);//自定义
Method systemMethod =class_getInstanceMethod(class, system);
Method customMethod =class_getInstanceMethod(class, custom);
class_addMethod(class, custom,method_getImplementation(customMethod),method_getTypeEncoding(customMethod));
method_exchangeImplementations(systemMethod,class_getInstanceMethod(class, custom));
}
- (id)safeobjectAtIndex:(NSInteger)index {
if (index >self.count -1) {
NSLog(@"数组越界了");
returnnil;
}else { //返回已经调换过的方法
return [selfsafeobjectAtIndex:index];
}
}
- 分类使用runtime交换方法
- Swift 中使用runtime交换方法实现
- runtime 方法交换
- runtime 方法交换
- Runtime -- 交换方法
- runtime交换方法
- runtime方法交换
- Runtime 学习-方法交换
- runtime 方法交换
- Runtime消息机制,交换方法,动态添加方法,分类添加属性
- XZ_iOS之Runtime使用运行时交换方法
- 工具类:防止数组越界崩溃问题(NSArray 分类/runtime 用法3:交换方法)
- ios runtime 交换方法实现
- ios RunTime之方法交换
- RunTime交换方法的实现
- Runtime(交换方法)笔记
- iOS:runtime的使用(动态添加方法、关联方法、交换方法、遍历私有属性)
- runtime之实现方法交换(简单版本)
- 从零学SLAM
- 【自考总结—16年4.17】
- linux基础之 spi驱动程序
- Unity 官方案例 Roll a ball
- 斐波那契图形
- 分类使用runtime交换方法
- maven 将本地jar包引入本地仓库
- Notepad++ 自定义 httpd.conf 文件语法高亮
- 怎么在几何画板中导入图片
- 文章标题
- 获取验证码倒计时
- 数据总线的带宽
- caffe学习2-LeNet网络
- 不将visio的白色背景复制到ppt上