//方式1 创建线程
NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(demo) object:nil];
//手动开启
[thread start];
//方式2 创建线程并启动线程
[NSThread detachNewThreadSelector:@selector(demo) toTarget:self withObject:nil];
//方式3 创建线程
[self performSelectorInBackground:@selector(demo) withObject:nil];
//方式4 创建线程执行带参数的方法
NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(demo:) object:@"aabb"];
[thread start];
}
- (void)demo:(NSString *)param {
NSLog(@"hello %@",param);
}
//线程执行的方法
- (void)demo {
NSLog(@"hello %@",[NSThread currentThread]);
}