/*
* 创建线程的方式1
*/
- (void)createThread1
{
// 创建线程
NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(download) object:nil];
// // 起线程名字
// thread.name = @"下载线程";
// 启动线程(调用self的download方法)
[thread start];
}
/*
* 创建线程的方式2
*/
- (void)createThread2
{
// 从当前线程中分离出一条线程
[NSThread detachNewThreadSelector:@selector(download:) toTarget:self withObject:@"http://awdawdaw"];
// withObject:传参
}
/*
* 创建线程的方式3:隐式创建
*/
- (void)createThread3
{
// 这两个不会创建线程,在当前线程进行
// [self performSelector:@selector(download:) withObject:@"http://afaf"];
// [self download:@"http://awdaf"];
[self performSelectorInBackground:@selector(download:) withObject:@"http://awdaf"];
// self performSelector:@selector(download:) onThread:[on mainThread] withObject:<#(id)#> waitUntilDone:<#(BOOL)#> modes:<#(NSArray *)#>
}