OC 运行时
来源:互联网 发布:知乎 人生目标 编辑:程序博客网 时间:2024/05/04 01:51
- #import <objc/objc-class.h>
- // create a class with no methods
- @interface EmptyClass : NSObject { }
- @end
- @implementation EmptyClass
- @end
- // define the function to add as a method
- id sayHello ( id self, SEL _cmd,... )
- {
- NSLog (@"Hello");
- }
- void addMethod ()
- {
- struct objc_method myMethod; <span style="white-space:pre"> </span>//0 创建method实例
- myMethod.method_name = sel_registerName("sayHello"); <span style="white-space:pre"> </span>//1.0 为函数名赋值
- myMethod.method_imp = sayHello; <span style="white-space:pre"> </span>//1.1 为函数实现赋值
- struct objc_method_list * myMethodList;
- myMethodList = malloc (sizeof(struct objc_method_list));
- myMethodList->method_count = 1;
- myMethodList->method_list[0] = myMethod;<span style="white-space:pre"> </span>//2 将自定义的函数实例添加到 list中
- class_addMethods ( [EmptyClass class], myMethodList );//3 将list绑定到类上面
- // 调用
- EmptyClass * instance = [[EmptyClass alloc] init];
- [instance sayHello];
- [instance release];
- }
0 0
- OC 运行时
- OC 运行时系统
- OC 运行时 (一)
- OC 运行时 (二)
- OC 运行时 (三)
- OC运行时简介
- OC运行时交互
- OC运行时消息
- OC运行时编程指南
- OC运行时编程指南
- OC运行时编程指南
- OC中的runtime运行时
- OC运行时编程指南
- 浅谈OC运行时(RunTime)
- OC运行时Runtime探究
- 函数替换 oc的运行时
- OC运行时动态创建类
- OC消息机制和动态运行时
- IOCP之accept、AcceptEx、WSAAccept的区别
- 腾讯实习招聘模拟题
- GCC使用入门
- 在web项目启动时,执行某个方法
- J2EE系列:再谈IE的浏览器模式和文档模式
- OC 运行时
- Nginx 在Linux 配置高并发TCP连接
- 去掉火狐浏览器书签文件夹的箭头。
- 2.awesomeplayer结构分析
- android 横竖屏
- 双进程保护及实现
- 通过window系统定时任务备份数据库
- rfid理论基础知识要点
- Launch Screen在iOS7/8中的实现