效果如下:
ViewController.h
1#import<UIKit/UIKit.h>23@interfaceViewController : UITableViewController4@PRoperty (copy, nonatomic) NSArray *arrSampleName;56- (instancetype)initWithSampleNameArray:(NSArray *)arrSampleName;78@end
ViewController.m
1#import"ViewController.h"2#import"FirstSampleViewController.h"3#import"SecondSampleViewController.h"45@interfaceViewController ()6- (void)layoutUI;7@end89@implementationViewController10- (void)viewDidLoad {11[super viewDidLoad];1213[self layoutUI];14}1516- (void)didReceiveMemoryWarning {17[super didReceiveMemoryWarning];18//Dispose of any resources that can be recreated.19}2021- (instancetype)initWithSampleNameArray:(NSArray *)arrSampleName {22if(self =[super initWithStyle:UITableViewStyleGrouped]) {23self.navigationItem.title =@"多线程开发之二 NSOperation";24self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回首页"style:UIBarButtonItemStylePlain target:nil action:nil];2526_arrSampleName =arrSampleName;27}28returnself;29}3031- (void)layoutUI {32}3334#pragmamark - UITableViewController相关方法重写35- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {36return0.1;37}3839- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {40return1;41}4243- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {44return[_arrSampleName count];45}4647- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {48staticNSString *cellIdentifier =@"cell";49UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:cellIdentifier];50if(!cell) {51cell =[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];52}53cell.textLabel.text =_arrSampleName[indexPath.row];54returncell;55}5657- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {58switch(indexPath.row) {59case0: {60FirstSampleViewController *firstSampleVC = [FirstSampleViewControllernew];61[self.navigationController pushViewController:firstSampleVC animated:YES];62
break;63}64case1: {65SecondSampleViewController *secondSampleVC = [SecondSampleViewControllernew];66[self.navigationController pushViewController:secondSampleVC animated:YES];67
break;68}69default:70
break;71}72}7374@end
UIImage+RescaleImage.h
1#import<UIKit/UIKit.h>23@interfaceUIImage (RescaleImage)4/**5* 根据宽高大小,获取对应的缩放图片6*7* @param size 宽高大小8*9* @return 对应的缩放图片10*/11- (UIImage *)rescaleImageToSize:(CGSize)size;1213@end
UIImage+RescaleImage.m
1#import"UIImage+RescaleImage.h"23@implementationUIImage (RescaleImage)45- (UIImage *)rescaleImageToSize:(CGSize)size {6CGRect rect = CGRectMake(0.0,0.0, size.width, size.height);78UIGraphicsBeginImageContext(rect.size);9[self drawInRect:rect];10UIImage *imgScale =UIGraphicsGetImageFromCurrentImageContext();11UIGraphicsEndImageContext();1213returnimgScale;14}1516@end
Common.h
1#import<Foundation/Foundation.h>23@interfaceCommon : NSObject4+ (NSURL *)randomImageURL;56@end
Common.m
1#import"Common.h"23@implementationCommon45+ (NSURL *)randomImageURL {6NSUInteger randomVal = (arc4random() %20) +1;//1-20的随机数7NSString *randomValStr = [NSString stringWithFormat:@"%lu", (unsignedlong)randomVal];8if(randomVal <10) {9randomValStr = [@"0"stringByAppendingString:randomValStr];10}1112NSString *imageURLStr = [NSString stringWithFormat:@"http://images.apple.com/v/watch/e/apple-watch/images/collection_%@_large.jpg", randomValStr];13return[NSURL URLWithString:imageURLStr];14}1516@end
FirstSampleViewController.h
1#import<UIKit/UIKit.h>23@interfaceFirstSampleViewController : UIViewController4@property (assign, nonatomic) CGSize rescaleImageSize;56@property (strong, nonatomic) IBOutlet UIImageView *imgV;7@property (strong, nonatomic) IBOutlet UIButton *btnLoadImage;89@end
FirstSampleViewController.m
1#import"FirstSampleViewController.h"2#import"UIImage+RescaleImage.h"3#import"Common.h"45@interfaceFirstSampleViewController ()6- (void)layoutUI;7- (void)updateImage:(NSData *)imageData;8- (void)loadImageFromNetwork;9@end1011@implementationFirstSampleViewController1213- (void)viewDidLoad {14[super viewDidLoad];1516[self layoutUI];17}1819- (void)didReceiveMemoryWarning {20[super didReceiveMemoryWarning];21//Dispose of any resources that can be recreated.22}2324- (void)dealloc {25_imgV.image =nil;26}2728- (void)layoutUI {29CGFloat width = [[UIScreen mainScreen] bounds].size.width;//bounds 返回整个屏幕大小;applicationFrame 返回去除状态栏后的屏幕大小30CGFloat height = width *438.0/366.0;31constCGFloat percentVal =3.0/4.0;//以屏幕宽度的3/4比例显示32_rescaleImageSize = CGSizeMake(width * percentVal, height *percentVal);3334//NSString *path = [[NSBundle mainBundle] pathForResource:@"PictureNo@2x" ofType:@"png"];35//_imgV.image = [UIImage imageWithContentsOfFile:path];3637_btnLoadImage.tintColor =[UIColor darkGrayColor];38_btnLoadImage.layer.masksToBounds =YES;39_btnLoadImage.layer.cornerRadius =10.0;40_btnLoadImage.layer.borderColor =[UIColor grayColor].CGColor;41_btnLoadImage.layer.borderWidth =1.0;42}4344- (void)updateImage:(NSData *)imageData {45UIImage *img =[UIImage imageWithData:imageData];46_imgV.image =[img rescaleImageToSize:_rescaleImageSize];47}4849- (void)loadImageFromNetwork {50NSURL *url =[Common randomImageURL];51NSData *data =[NSData dataWithContentsOfURL:url];5253//mainQueue 是 UI 主线程,调用主线程队列的方法进行操作54[[NSOperationQueue mainQueue] addOperationWithBlock:^{55[self updateImage:data];56}];57}5859- (IBAction)loadImage:(id)sender {60//方法一:使用 NSInvocationOperation61//NSInvocationOperation *invocationOperation = [[NSInvocationOperation alloc]62//initWithTarget:self63//selector:@selector(loadImageFromNetwork)64//object:nil];65//NSOperationQueue *operationQueue = [NSOperationQueue new];//操作队列66//[operationQueue addOperation:invocationOperation];676869//方法二:使用 NSBlockOperation70NSBlockOperation *blockOperation = [NSBlockOperation blockOperationWithBlock:^{71[self loadImageFromNetwork];72}];73[blockOperation addExecutionBlock:^{//还可以为 blockOperation 添加代码块;多个代码块会被分到多个线程去执行,存在两个代码块被分配到同一个线程执行的情况74NSLog(@"代码块");75}];76[blockOperation addExecutionBlock:[blockOperation executionBlocks][1]];//这里可以调用他的 executionBlocks 获取到添加的代码块数组;上面打印的内容「代码块」会被执行两次7778[blockOperation setCompletionBlock:^{79NSLog(@"所有代码块操作执行完毕后(无论已取消还是已完成),做一些事情,只执行一次");80}];8182//[blockOperation start];//使用 start 方法,则此操作在主线程中执行;一般不这样操作,而是添加到操作队列中83NSOperationQueue *operationQueue = [NSOperationQueuenew];//操作队列84[operationQueue addOperation:blockOperation];//添加到操作队列,这时队列会开启一个线程去执行此操作;一个线程可以执行多个操作8586//方法三:直接使用 NSOperationQueue87//NSOperationQueue *operationQueue = [NSOperationQueue new];//操作队列88//[operationQueue addOperationWithBlock:^{89//[self loadImageFromNetwork];90//}];91}9293@end
FirstSampleViewController.xib
1<?xmlversion="1.0" encoding="UTF-8" standalone="no"?>2<documenttype="com.apple.InterfaceBuilder3.CocoaTouch.XIB"version="3.0"toolsVersion="7706"systemVersion="14E46"targetRuntime="iOS.CocoaTouch"propertyaccessControl="none"useAutolayout="YES"useTraitCollections="YES">3<dependencies>4<deploymentidentifier="iOS"/>5<plugInidentifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin"version="7703"/>6</dependencies>7<objects>8<placeholderplaceholderIdentifier="IBFilesOwner"id="-1"userLabel="File's Owner"customClass="FirstSampleViewController">9<connections>10<outletproperty="btnLoadImage"destination="sLs-f1-Gzc"id="kX8-J0-v0V"/>11<outletproperty="imgV"destination="4Qp-uk-KAb"id="RM3-Ha-glh"/>12<outletproperty="view"destination="i5M-Pr-FkT"id="sfx-zR-JGt"/>13</connections>14</placeholder>15<placeholderplaceholderIdentifier="IBFirstResponder"id="-2"customClass="UIResponder"/>16<viewclearsContextBeforeDrawing="NO"contentMode="scaleToFill"id="i5M-Pr-FkT">17<rectkey="frame"x="0.0"y="0.0"width="600"height="600"/>18<autoresizingMaskkey="autoresizingMask"widthSizable="YES"heightSizable="YES"/>19<subviews>20<imageViewuserInteractionEnabled="NO"contentMode="scaleToFill"horizontalHuggingPriority="251"verticalHuggingPriority="251"image="PictureNo.png"translatesAutoresizingMaskIntoConstraints="NO"id="4Qp-uk-KAb">21<rectkey="frame"x="205"y="225"width="190"height="150"/>22<constraints>23<constraintfirstAttribute="height"constant="150"id="Sip-Wd-idU"/>24<constraintfirstAttribute="height"constant="150"id="VwM-i1-atB"/>25<constraintfirstAttribute="width"constant="190"id="mUh-Bu-tUd"/>26<constraintfirstAttribute="width"constant="190"id="mdJ-1c-QFa"/>27<constraintfirstAttribute="width"constant="190"id="sVS-bU-Ty9"/>28<constraintfirstAttribute="height"constant="150"id="uMG-oN-J56"/>29<constraintfirstAttribute="height"constant="150"id="vws-Qw-UrB"/>30</constraints>31<variationkey="default">32<maskkey="constraints">33<excludereference="SIp-Wd-idU"/>34<excludereference="VwM-i1-atB"/>35<excludereference="mUh-Bu-tUd"/>36<excludereference="mdJ-1c-QFa"/>37<excludereference="sVS-bU-Ty9"/>38<excludereference="uMG-oN-J56"/>39<excludereference="vws-Qw-UrB"/>40</mask>41</variation>42</imageView>43<buttonopaque="NO"contentMode="scaleToFill"contentHorizontalAlignment="center"contentVerticalAlignment="center"buttonType="roundedRect"lineBreakMode="middleTruncation"translatesAutoresizingMaskIntoConstraints="NO"id="sLs-f1-Gzc">44<rectkey="frame"x="230"y="500"width="140"height="50"/>45<constraints>46<constraintfirstAttribute="width"constant="140"id="1jv-9K-mdH"/>47<constraintfirstAttribute="height"constant="50"id="Q2w-vR-9ac"/>48</constraints>49<statekey="normal"title="加载网络图片">50<colorkey="titleShadowColor"white="0.5"alpha="1"colorSpace="calibratedWhite"/>51</state>52<connections>53<actionselector="loadImage:"destination="-1"eventType="touchUpInside"id="fdy-Ln-5oS"/>54</connections>55</button>56</subviews>57<colorkey="backgroundColor"white="1"alpha="1"colorSpace="custom"customColorSpace="calibratedWhite"/>58<constraints>59<constraintfirstItem="4Qp-uk-KAb"firstAttribute="leading"secondItem="i5M-Pr-FkT"secondAttribute="leading"constant="205"id="2a2-mS-WFa"/>60<constraintfirstItem="sLs-f1-Gzc"firstAttribute="top"secondItem="i5M-Pr-FkT"secondAttribute="top"id="ES4-wl-RBz"/>61<constraintfirstItem="4Qp-uk-KAb"firstAttribute="centerY"secondItem="i5M-Pr-FkT"secondAttribute="centerY"id="MUJ-WA-sUf"/>62<constraintfirstItem="4Qp-uk-KAb"firstAttribute="centerX"secondItem="sLs-f1-Gzc"secondAttribute="centerX"id="Q8a-1k-DzJ"/>63<constraintfirstAttribute="bottom"secondItem="4Qp-uk-KAb"secondAttribute="bottom"constant="71"id="V0a-9y-Dwa"/>64<constraintfirstAttribute="bottom"secondItem="sLs-f1-Gzc"secondAttribute="bottom"constant="50"id="VMG-CV-eeq"/>65<constraintfirstItem="4Qp-uk-KAb"firstAttribute="top"secondItem="i5M-Pr-FkT"secondAttribute="top"constant="-71"id="gqW-Wq-4Zv"/>66<constraintfirstItem="sLs-f1-Gzc"firstAttribute="centerX"secondItem="i5M-Pr-FkT"secondAttribute="centerX"id="kNf-6d-EJ8"/>67</constraints>68<variationkey="default">69<maskkey="constraints">70<excludereference="2a2-mS-WFa"/>71<excludereference="V0a-9y-Dwa"/>72<excludereference="gqW-Wq-4Zv"/>73<excludereference="ES4-wl-RBz"/>74</mask>75</variation>76</view>77</objects>78<resources>79<imagename="PictureNo.png"width="190"height="150"/>80</resources>81</document>
SecondSampleViewController.h
1#import<UIKit/UIKit.h>23@interfaceSecondSampleViewController : UIViewController4@property (assign, nonatomic) CGSize rescaleImageSize;5@property (strong, nonatomic) NSMutableArray *mArrImageView;67@property (strong, nonatomic) IBOutlet UIButton *btnLoadImage;89@end
SecondSampleViewController.m
1#import"SecondSampleViewController.h"2#import"UIImage+RescaleImage.h"3#import"Common.h"45#definekRowCount 46#definekColumnCount 37#definekCellSpacing 10.089@interfaceSecondSampleViewController ()10- (void)layoutUI;11- (void)updateImage:(NSData *)imageData withImageIndex:(NSInteger)imageIndex;12-(NSData *)requestData:(NSInteger)imageIndex;13- (void)loadImageFromNetwork:(NSInteger)imageIndex;14@end1516@implementationSecondSampleViewController1718- (void)viewDidLoad {19[super viewDidLoad];2021[self layoutUI];22}2324- (void)didReceiveMemoryWarning {25[super didReceiveMemoryWarning];26//Dispose of any resources that can be recreated.27}2829- (void)dealloc {30_mArrImageView =nil;31}3233- (void)layoutUI {34CGFloat width = ([[UIScreen mainScreen] bounds].size.width - ((kColumnCount +1) * kCellSpacing)) /kColumnCount;35_rescaleImageSize =CGSizeMake(width, width);3637CGFloat heightOfStatusAndNav =20.0+44.0;38NSString *path = [[NSBundle mainBundle] pathForResource:@"PictureNo@2x"ofType:@"png"];39UIImage *img =[UIImage imageWithContentsOfFile:path];40_mArrImageView = [NSMutableArray arrayWithCapacity:kRowCount *kColumnCount];41//初始化多个图片视图42for(NSUInteger i=0; i<kRowCount; i++) {43for(NSUInteger j=0; j<kColumnCount; j++) {44UIImageView *imgV =[[UIImageView alloc] initWithFrame:45CGRectMake(_rescaleImageSize.width * j + kCellSpacing * (j+1),46_rescaleImageSize.height * i + kCellSpacing * (i+1) +heightOfStatusAndNav,47_rescaleImageSize.width,48_rescaleImageSize.height)];49imgV.image =img;50[self.view addSubview:imgV];51[_mArrImageView addObject:imgV];52}53}5455_btnLoadImage.tintColor =[UIColor darkGrayColor];56_btnLoadImage.layer.masksToBounds =YES;57_btnLoadImage.layer.cornerRadius =10.0;58_btnLoadImage.layer.borderColor =[UIColor grayColor].CGColor;59_btnLoadImage.layer.borderWidth =1.0;60}6162- (void)updateImage:(NSData *)imageData withImageIndex:(NSInteger)imageIndex {63UIImage *img =[UIImage imageWithData:imageData];64UIImageView *imgVCurrent =_mArrImageView[imageIndex];65imgVCurrent.image =[img rescaleImageToSize:_rescaleImageSize];66}6768-(NSData *)requestData:(NSInteger)imageIndex {69//对于多线程操作,建议把线程操作放到 @autoreleasepool 中70@autoreleasepool {71NSURL *url =[Common randomImageURL];72NSData *data =[NSData dataWithContentsOfURL:url];73returndata;74}75}7677- (void)loadImageFromNetwork:(NSInteger)imageIndex {78/*79对比之前 NSThread 加载图片,你会发现核心代码简化了不少,有两点值得提的:80(1)使用 NSBlockOperation 方法,所有的操作不必单独定义方法,同时解决了只能传递一个参数的问题。类似的操作,例如:调用主线程队列的 addOperationWithBlock: 方法进行 UI 更新,不用再定义一个参数实体类来进行参数传递(之前必须定义一个 KMImageData 解决只能传递一个参数的问题)。81(2)使用 NSOperation 进行多线程开发可以设置最大并发操作数,有效的对操作进行控制(如 Demo 的代码设置最大并发操作数为5,则图片最多是五个一次加载的)。82*/83NSLog(@"Current thread:%@", [NSThread currentThread]);8485//mainQueue 是 UI 主线程,调用主线程队列的方法进行操作86[[NSOperationQueue mainQueue] addOperationWithBlock:^{87[self updateImage:[self requestData:imageIndex] withImageIndex:imageIndex];88}];89}9091- (IBAction)loadImage:(id)sender {92NSOperationQueue *operationQueue = [NSOperationQueuenew];93operationQueue.maxConcurrentOperationCount =5;//设置最大并发操作数9495NSUInteger len = kRowCount *kColumnCount;96NSBlockOperation *lastBlockOperation = [NSBlockOperation blockOperationWithBlock:^{97[self loadImageFromNetwork:len -1];98}];99100for(NSUInteger i=0; i<len -1; i++) {101NSBlockOperation *blockOperation = [NSBlockOperation blockOperationWithBlock:^{102[self loadImageFromNetwork:i];103}];104105//实现控制「操作执行顺序」,例如:控制最后一个操作第一个执行,这里设置操作的依赖关系为:最后一张图片加载操作完成后才执行106//PS:注意请勿进行循环依赖,否则循环依赖相关的操作是不会被执行的107//这里添加依赖关系;其相对应的移除方法:- (void)removeDependency:(NSOperation *)op;108[blockOperation addDependency:lastBlockOperation];109110//另外添加操作对象实例数组的方法:- (void)addOperations:(NSArray *)ops waitUntilFinished:(BOOL)wait;111[operationQueue addOperation:blockOperation];112}113114[operationQueue addOperation:lastBlockOperation];115116/*117lastBlockOperation.queuePriority = NSOperationQueuePriorityVeryHigh; //在某个操作队列中的队列优先级;这样可以提高他被优先加载的机率,但是他也未必就第一个加载;所以要实现控制「操作执行顺序」,就得用设置操作的依赖关系的方式118119typedef enum : NSInteger {120NSOperationQueuePriorityVeryLow = -8,121NSOperationQueuePriorityLow = -4,122NSOperationQueuePriorityNormal = 0,123NSOperationQueuePriorityHigh = 4,124NSOperationQueuePriorityVeryHigh = 8125} NSOperationQueuePriority;126*/127}128129@end
SecondSampleViewController.xib
1<?xml version="1.0" encoding="UTF-8" standalone="no"?>2<documenttype="com.apple.InterfaceBuilder3.CocoaTouch.XIB"version="3.0"toolsVersion="7706"systemVersion="14E46"targetRuntime="iOS.CocoaTouch"propertyAccessControl="none"useAutolayout="YES"useTraitCollections="YES">3<dependencies>4<deploymentidentifier="iOS"/>5<plugInidentifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin"version="7703"/>6</dependencies>7<objects>8<placeholderplaceholderIdentifier="IBFilesOwner"id="-1"userLabel="File's Owner"customClass="SecondSampleViewController">9<connections>10<outletproperty="btnLoadImage"destination="F5h-ZI-gGL"id="I40-e2-bAa"/>11<outletproperty="view"destination="i5M-Pr-FkT"id="sfx-zR-JGt"/>12</connections>13</placeholder>14<placeholderplaceholderIdentifier="IBFirstResponder"id="-2"customClass="UIResponder"/>15<viewclearsContextBeforeDrawing="NO"contentMode="scaleToFill"id="i5M-Pr-FkT">16<rectkey="frame"x="0.0"y="0.0"width="600"height="600"/>17<autoresizingMaskkey="autoresizingMask"widthSizable="YES"heightSizable="YES"/>18<subviews>19<buttonopaque="NO"contentMode="scaleToFill"contentHorizontalAlignment="center"contentVerticalAlignment="center"buttonType="roundedRect"lineBreakMode="middleTruncation"translatesAutoresizingMaskIntoConstraints="NO"id="F5h-ZI-gGL">20<rectkey="frame"x="230"y="530"width="140"height="50"/>21<constraints>22<constraintfirstAttribute="height"constant="50"id="HWd-Xc-Wk7"/>23<constraintfirstAttribute="width"constant="140"id="vrH-qE-PNK"/>24</constraints>25<statekey="normal"title="加载网络图片">26<colorkey="titleShadowColor"white="0.5"alpha="1"colorSpace="calibratedWhite"/>27</state>28<connections>29<actionselector="loadImage:"destination="-1"eventType="touchUpInside"id="Hgw-q8-lHy"/>30</connections>31</button>32</subviews>33<colorkey="backgroundColor"white="1"alpha="1"colorSpace="custom"customColorSpace="calibratedWhite"/>34<constraints>35<constraintfirstAttribute="bottom"secondItem="F5h-ZI-gGL"secondAttribute="bottom"constant="20"id="jPY-fY-9XJ"/>36<constraintfirstAttribute="centerX"secondItem="F5h-ZI-gGL"secondAttribute="centerX"id="rH1-sV-pST"/>37</constraints>38</view>39</objects>40</document>
AppDelegate.h
1#import<UIKit/UIKit.h>23@interfaceAppDelegate : UIResponder <UIApplicationDelegate>45@property (strong, nonatomic) UIWindow *window;6@property (strong, nonatomic) UINavigationController *navigationController;78@end
AppDelegate.m
1#import"AppDelegate.h"2#import"ViewController.h"34@interfaceAppDelegate ()56@end78@implementationAppDelegate91011- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {12_window =[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];13ViewController *viewController = [[ViewController alloc] initWithSampleNameArray:@[@"请求单张网络图片(解决线程阻塞)",@"请求多张网络图片(多个线程并发)"]];14_navigationController =[[UINavigationController alloc] initWithRootViewController:viewController];15_window.rootViewController =_navigationController;16//[_window addSubview:_navigationController.view];//当_window.rootViewController关联时,这一句可有可无17[_window makeKeyAndVisible];18returnYES;19}2021- (void)applicationWillResignActive:(UIApplication *)application {22}2324- (void)applicationDidEnterBackground:(UIApplication *)application {25}2627- (void)applicationWillEnterForeground:(UIApplication *)application {28}2930- (void)applicationDidBecomeActive:(UIApplication *)application {31}3233- (void)applicationWillTerminate:(UIApplication *)application {34}3536@end
输出结果:
12015-08-2800:26:36.878NSOperationDemo[4228:48976] 代码块22015-08-2800:26:36.878NSOperationDemo[4228:48977] 代码块32015-08-2800:26:37.366NSOperationDemo[4228:48976] 所有代码块操作执行完毕后(无论已取消还是已完成),做一些事情,只执行一次452015-08-2800:26:42.505NSOperationDemo[4228:48860] Current thread:<NSThread:0x7fbd1bd335b0>{number =3, name = (null)}62015-08-2800:26:42.506NSOperationDemo[4228:48978] Current thread:<NSThread:0x7fbd1be0ad90>{number =4, name = (null)}72015-08-2800:26:42.507NSOperationDemo[4228:48990] Current thread:<NSThread:0x7fbd1e047390>{number =5, name = (null)}82015-08-2800:26:42.507NSOperationDemo[4228:48990] Current thread:<NSThread:0x7fbd1e047390>{number =5, name = (null)}92015-08-2800:26:42.507NSOperationDemo[4228:48978] Current thread:<NSThread:0x7fbd1be0ad90>{number =4, name = (null)}102015-08-2800:26:42.507NSOperationDemo[4228:49025] Current thread:<NSThread:0x7fbd1be07c70>{number =6, name = (null)}112015-08-2800:26:42.508NSOperationDemo[4228:48978] Current thread:<NSThread:0x7fbd1be0ad90>{number =4, name = (null)}122015-08-2800:26:42.508NSOperationDemo[4228:49025] Current thread:<NSThread:0x7fbd1be07c70>{number =6, name = (null)}132015-08-2800:26:42.508NSOperationDemo[4228:48978] Current thread:<NSThread:0x7fbd1be0ad90>{number =4, name = (null)}142015-08-2800:26:42.508NSOperationDemo[4228:48990] Current thread:<NSThread:0x7fbd1e047390>{number =5, name = (null)}152015-08-2800:26:42.508NSOperationDemo[4228:48976] Current thread:<NSThread:0x7fbd1e0335f0>{number =7, name = (null)}162015-08-2800:26:42.508NSOperationDemo[4228:48978] Current thread:<NSThread:0x7fbd1be0ad90>{number =4, name = (null)}