一 位运算技巧
在设计枚举的时候 ,可以传多值
//typedef enum {
// MJOptionsOne = 1, // 0b0001
// MJOptionsTwo = 2, // 0b0010
// MJOptionsThree = 4, // 0b0100
// MJOptionsFour = 8 // 0b1000
//} MJOptions;
typedef enum {
// MJOptionsNone = 0, // 0b0000
MJOptionsOne = 1<<0, // 0b0001
MJOptionsTwo = 1<<1, // 0b0010
MJOptionsThree = 1<<2, // 0b0100
MJOptionsFour = 1<<3 // 0b1000
} MJOptions;
- (void)setOptions:(MJOptions)options
{
if (options & MJOptionsOne) {
NSLog(@"包含了MJOptionsOne");
}
if (options & MJOptionsTwo) {
NSLog(@"包含了MJOptionsTwo");
}
if (options & MJOptionsThree) {
NSLog(@"包含了MJOptionsThree");
}
if (options & MJOptionsFour) {
NSLog(@"包含了MJOptionsFour");
}
}
- (void)viewDidLoad {
[super viewDidLoad];
// [self performSelector:@selector(test)];
//
// [person performSelector:@selector(test)];
[self setOptions: MJOptionsOne | MJOptionsFour];
[self setOptions: MJOptionsOne + MJOptionsTwo + MJOptionsFour];
//
// self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin;
//
// NSKeyValueObservingOptions options = NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld;
//
// [self addObserver:self forKeyPath:@"age" options:options context:NULL];
}
二 : 细节
isa指针 含义
源码结构
如果没有c++析构函数,或者关联对象,将不会做下面框框内的操作,释放更快
三 : class 结构解析
内存结构
class_rw_t下面部分细节
class_ro_t
网友评论