iOS细节点(常更新)
2020-05-21 本文已影响0人
Silence_xl
1、__unsafe_unretained和__weak的区别
都是弱引用,__unsafe_unretained指向对象的指针置空后是野指针,访问后产生BAD_ACCESS,__weak指向对象的指针置空后为nil。YYCache中双向链表中有使用,主要是对对象的释放有把握,提升性能。
2、iOS中的数据存储方式
Plist(NSArray,NSDictionary)
Preference(偏好设置,NSUserDefault)
NSCoding(NSKeyedArchiver,NSKeyedUnarchiver)
SQLite3
Core Data
3、RunLoop
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
[self timer1];
}
-(void)timer1
{
//创建定时器对象
NSTimer *timer = [NSTimer timerWithTimeInterval:2.0 target:self selector:@selector(run) userInfo:nil repeats:YES];
//添加到runloop中
//Mode:runloop到运行模式
//把定时器对象添加到runloop中,并指定运行模式为默认
//当滚动textView的时候,主运行循环会切换运行模式(默认-》界面追踪运行模式)
[[NSRunLoop currentRunLoop] addTimer:timer forMode:UITrackingRunLoopMode];
}
-(void)run
{
NSLog(@"run---%@",[NSRunLoop currentRunLoop].currentMode);
}
3、位运算
& 按位&,都是1才是1。
| 按位|,有一个是1就是1。