OC中,創(chuàng)建線程的三種方法:
1、NSThread ;特點:使用更加面向?qū)ο?,簡單易用,可直接操作線層對象
創(chuàng)建線程方法一:NSThread * thread = [[NSThread alloc]initWithTarget:self ?selected:@selected(run) object:nil];
【注釋】initWithTarget:在哪里執(zhí)行;object:參數(shù) ; 之后會告訴CPU準備就緒,隨時接受CUP的調(diào)度,當CUP調(diào)度當前線程之后,就會在線程的thread方法中執(zhí)行self的run方法;
創(chuàng)建線程方法二:[NSThread detachNewThreadSelector:@selector(run) toTarget:self withObject:nil];
創(chuàng)建線層方法三:[self performSelectorInBackground:@selector(run) withObject:nil];
方法二與方法三的優(yōu)點:簡單快捷;缺點:無法對線程進行更詳細的設(shè)置;
2、GCD , 目的是取代NSThread等線程技術(shù)、充分利用設(shè)備的多核;
3、NSOperation,基于GCD、比GCD多了一些更簡單試用的功能,使用起來更加面向?qū)ο?br>