NSThread

作者: CaptainRoy | 来源:发表于2019-07-16 11:01 被阅读0次
创建使用线程
  • 第一种方式 创建手动启动线程
NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(runThread) object:NULL];
[thread start];
-(void)runThread
{
    NSLog(@" %@ ",[NSThread currentThread]);
}
  • 第二种 创建完成自动执行线程
[NSThread detachNewThreadSelector:@selector(runThread) toTarget:self withObject:NULL];
  • 第三种
[self performSelectorInBackground:@selector(runThread) withObject:NULL];
相关方法
[NSThread mainThread]; // 获取主线程
[NSThread mainThread]; // 判断是否是主线程
NSThread *thread = [NSThread currentThread];
[thread isMainThread]; // 判断是否是主线程
thread.name = @"";// 线程名字

相关文章

网友评论

      本文标题:NSThread

      本文链接:https://www.haomeiwen.com/subject/pkdzkctx.html