函数替换 oc的运行时
来源:互联网 发布:团队协作工具 知乎 编辑:程序博客网 时间:2024/06/11 09:12
BOOL swizzle(Class c,SEL origSelector, SEL newSelector){ Method origMethod = class_getInstanceMethod(c, origSelector); Method newMethod = class_getInstanceMethod(c, newSelector); if (origMethod && newMethod) { if (class_addMethod(c, origSelector, method_getImplementation(newMethod), method_getTypeEncoding(newMethod))) { class_replaceMethod(c, newSelector, method_getImplementation(origMethod), method_getTypeEncoding(origMethod)); } else { method_exchangeImplementations(origMethod, newMethod); } return YES; } return NO;}
以下是替换后的使用:
SEL ors = @selector(haha);
SEL news = @selector(oooo);
Class c = NSClassFromString(@"Test1");
BOOL succesed = swizzle(c,ors,news);
[self haha];
- 函数替换 oc的运行时
- ios运行时替换函数
- OC中运行时的概念
- 关于OC运行时的整理
- OC 运行时
- OC 运行时系统
- OC 运行时 (一)
- OC 运行时 (二)
- OC 运行时 (三)
- OC运行时简介
- OC运行时交互
- OC运行时消息
- OC字符串的截取和替换
- OC-函数的私有化
- oc函数+ - 的区别
- OC 函数的使用
- OC的Runtime(运行时)机制的解析
- OC的Runtime(运行时)机制的解析
- 在Android中替换掉原有的HOME,实现自主的控制Launcher
- AT&T汇编与GCC内嵌汇编语法(转载)
- Application failed codesign verification警告
- 递归算法
- linux网络程序编程
- 函数替换 oc的运行时
- 容器
- Intent原理分析
- 三、代码的坏味道
- linux下修改文件权限.
- [转] 一生用10亿元也买不来的经商经验
- Quartz 2D相关知识
- windows API 操作注册表函数
- Android OpenGL ES 开发教程(24):Depth Buffer