OC中,创建线程的三种方法:
1、NSThread ;特点:使用更加面向对象,简单易用,可直接操作线层对象
创建线程方法一:NSThread * thread = [[NSThread alloc]initWithTarget:self selected:@selected(run) object:nil];
【注释】initWithTarget:在哪里执行;object:参数 ; 之后会告诉CPU准备就绪,随时接受CUP的调度,当CUP调度当前线程之后,就会在线程的thread方法中执行self的run方法;
创建线程方法二:[NSThread detachNewThreadSelector:@selector(run) toTarget:self withObject:nil];
创建线层方法三:[self performSelectorInBackground:@selector(run) withObject:nil];
方法二与方法三的优点:简单快捷;缺点:无法对线程进行更详细的设置;
2、GCD , 目的是取代NSThread等线程技术、充分利用设备的多核;
3、NSOperation,基于GCD、比GCD多了一些更简单试用的功能,使用起来更加面向对象