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>