你要知道的runtime都在这里
转载请注明出处 http://blog.csdn.net/u014205968/article/details/67639303
本文主要讲解runtime
相关知识,从原理到实践,由于包含内容过多分为以下五篇文章详细讲解,可自行选择需要了解的方向:
- 从runtime开始: 理解面向对象的类到面向过程的结构体
- 从runtime开始: 深入理解OC消息转发机制
- 从runtime开始: 理解OC的属性property
- 从runtime开始: 实践Category添加属性与黑魔法method swizzling
- 从runtime开始: 深入weak实现机理
本文是系列文章的第三篇文章从runtime开始: 理解OC的属性property,主要从runtime
出发讲解属性property
相关的底层实现和相关方法,由于之前的博客已经详细讲解了property
的底层实现,所以本文不再赘述,如有需要可以查看相关文章:iOS @property探究(一): 基础详解该文主要讲解property
的基础以及修饰符详解,iOS @property探究(二): 深入理解该文主要深入代码理解property
的底层实现,由于与本文的内容由很大的重复,因此本文不再赘述上述相关内容。
本文将会讲解一些runtime
操作属性的相关方法。
首先回顾一下相关代码以及与property
底层实现相关的两个结构体:
//OC自定义类的定义
@interface Person : NSObject
@property (nonatomic, copy) NSString* cjmName;
@property (nonatomic, assign) NSUInteger cjmAge;
@end
@implementation Person
@synthesize cjmName = _cjmName;
@synthesize cjmAge = _cjmAge;
@end
//clang转写为.cpp的相关代码
struct _prop_t {
const char *name;
const char *attributes;
};
static struct /*_prop_list_t*/ {
unsigned int entsize; // sizeof(struct _prop_t)
uns