1.upperBound(Type t)方法 /** * The "rvalue conversion". * The upper bound of most types is the type itself. Wildcards, on the other hand have upper and lower bounds. * @param t a type * @return the upper bound of the given type */ public Type uppe…
4.isSameType() 方法 /** * Is t the same type as s? */ public boolean isSameType(Type t, Type s) { return isSameType.visit(t, s); } 会对t为各种类型进行单独判断,下面来具体阐述. (1)t为Type类型 public Boolean visitType(Type t, Type s) { if (t == s) return true; if (s.tag >= firs…
5. Conversions and Promotions 5.1. Kinds of Conversion 5.1.1. Identity Conversion 5.1.2. Widening Primitive Conversion 5.1.3. Narrowing Primitive Conversion 5.1.4. Widening and Narrowing Primitive Conversion 5.1.5. Widening Reference Conversion 5.1.6…
接上一篇http://www.cnblogs.com/ddavidXu/p/5924049.html 转载来源http://www.jianshu.com/p/6b905584f536 http://southpeak.github.io/2014/10/30/objective-c-runtime-2/ 方法和消息  OC中对象调用方法,实际是给对象发送消息 SEL又叫选择器,是表示一个方法的selector的指针,其定义如下: typedef struct objc_selector *SE…
动态加载 #import"ViewController.h" #import"Person.h" @interfaceViewController() @end @implementationViewController - (void)viewDidLoad { [super viewDidLoad]; // performSelector:动态添加方法 Person*p = [[Person alloc]init]; //动态添加方法 //[p performS…
基础数据类型 SEL SEL又叫选择器,是表示一个方法的selector的指针,其定义如下: typedef struct objc_selector *SEL; objc_selector结构体的详细定义没有在<objc/runtime.h>头文件中找到.方法的selector用于表示运行时方法的名字.Objective-C在编译时,会依据每一个方法的名字.参数序列,生成一个唯一的整型标识(Int类型的地址),这个标识就是SEL.如下代码所示: 1 2 SEL sel1 = @selecto…
前面我们讨论了Runtime中对类和对象的处理,及对成员变量与属性的处理.这一章,我们就要开始讨论Runtime中最有意思的一部分:消息处理机制.我们将详细讨论消息的发送及消息的转发.不过在讨论消息之前,我们先来了解一下与方法相关的一些内容. 基础数据类型 SEL SEL又叫选择器,是表示一个方法的selector的指针,其定义如下: typedef struct objc_selector *SEL; objc_selector结构体的详细定义没有在<objc/runtime.h>头文件中找…
1 举例  我们实现一个Person类 然后Person 其实是没得对象方法eat:的 下面调用person的eat方法 程序是会奔溃的 那么需要借助运行时动态的添加方法 Person *p = [[Person alloc]init]; [p performSelector:@selector(eat:) withObject:@"鸡腿"]; 在perosn.m文件中进行实现运行时动态添加方法 // // Person.m // 运行时(动态添加方法) // // Created b…
如果一个类方法非常多,加载类到内存的时候也比较耗费资源,可以使用动态给某个类,添加方法解决.做到优化内存,节省资源的效果. // // Person.m // ResolveInstanceMethod // // Created by Doman on 17/3/23. // Copyright © 2017年 doman. All rights reserved. // #import "Person.h" #import <objc/message.h> @imple…
本文目录 1.Runtime简介 2.Runtime相关的头文件 3.技术点和应用场景 3_1.获取属性\成员变量列表 3_2.交换方法实现 3_3.类\对象的关联对象,假属性 3_4.动态添加方法,拦截未实现的方法 3_5.动态创建一个类 4.面试题 -1.Runtime简介 1.Runtime简介 因为Objc是一门动态语言,所以它总是想办法把一些决定工作从编译连接推迟到运行时.也就是说只有编译器是不够的,还需要一个运行时系统 (runtime system) 来执行编译后的代码.这就是 O…