iOS多线程介绍

2020-01-15 15:21:45于海丽

2)、在子线程中运行的Demo


-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//获取当前执行方法和当前线程
//number== 主线程
//number!= 其他线程、子线程、次线程
NSLog(@"%s----%@",__func__,[NSThread currentThread]);
//将耗时操作放在子线程中执行,不影响UI的操作
[self performSelectorInBackground:@selector(longTimeOperation) withObject:nil];
}
#pragma mark-耗时操作
-(void)longTimeOperation{
for (int i=; i<; i++) {
NSLog(@"%d",i);
}
}

以上内容是小编给大家介绍的ios多线程知识,希望对大家有所帮助!



注:相关教程知识阅读请移步到IOS开发频道。