- (void)viewDidLoad {
[super viewDidLoad];
dispatch_async(dispatch_get_global_queue(0, 0), ^{
//1.创建定时器
NSTimer *timer = [NSTimer timerWithTimeInterval:2.0 target:self selector:@selector(run) userInfo:nil repeats:YES];
//2.将Timer添加到RunLoop中
[[NSRunLoop currentRunLoop]addTimer:timer forMode:NSRunLoopCommonModes];
//3.让RunLoop运行起来
[[NSRunLoop currentRunLoop] run];//死循环,后面的代码不会执行
NSLog(@"+++++++++");
});
}
- (void)run {
//耗时操作
[NSThread sleepForTimeInterval:1.0];
NSLog(@"-------- %@",[NSThread currentThread]);
}