-
指针
- int *p = &age 定义且赋值
- *p 是取值
- **p 指向指针的指针
- 函数名即是函数地址
- 指向函数名的指针 (返回值类型)(*指针名)(参数类型)
-
SEL 的理解
- 每个类的方法列表都存储在类对象中
- 每个方法都有个与之一一对应的SEL类型的对象
- 根据SEL对象就可以找到对应的方法的地址,进而调用方法
- 定义为 typedef struct objc_selector *SEL
- an opaque type that represents a method selector
- _cmd 代表当前的方法
-
结构体
- 结构体类型的指针
- struct (结构体名)*(指针名)
- 结构体访问成员属性用 -> 箭头访问
- 类的底层是用struct去实现的、所以他的成员变量、实例变量实际上就是结构体的成员
- 而OC对象本身是一个指针(栈空间指针),
-
OC对象、在new 或者alloc init之后返回的是一个堆空间地址;所以在用的时候就是 指针、指向地址的数据; - 函数名就是函数地址:拿到了这个对象的指针、根据指针调用类内部的方法
- 创建一个对象、就是创建了一个对象指针、指向了堆空间的地址值;
-
new
-
new相当于alloc、init 的联合返回一个实例对象的
-
Allocates a new instance of the receiving class, sends it an init message, and returns the initialized object.
-
-
alloc
-
Returns a new instance of the receiving class.
-
Do not override
allocto include initialization code. Instead, implement class-specific versions ofinit...methods.
For historical reasons,
allocinvokesallocWithZone:. -
-
Class
-
An opaque type that represents an Objective-C class.
-
typedefstructobjc_class*Class
-












网友评论