1 //2 //VIEWCONTROLLER.M3 //05-GCD Deferred Call4 //5 //Created by Mac on 16/4/21.6 //copyright©2016 Year Mac. All rights reserved.7 //8 9 #import "ViewController.h"Ten One @interfaceViewcontroller () A - @end - the @implementationViewcontroller - -- (void) Viewdidload { - [Super Viewdidload]; + - } + A- (void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (Uievent *)Event { at - [self delay3]; - } - - /** - * Non-deferred calls in */ -- (void) DelayThread1 { to +dispatch_queue_t queue = Dispatch_get_global_queue (Dispatch_queue_priority_default,0); -Dispatch_after (Dispatch_time_now, queue, ^{ the *NSLog (@"delay = = =%@", [Nsthread CurrentThread]); $ });Panax Notoginseng } - /** the * Delay calls and turn on multithreading + */ A- (void) delayThread2 { the +dispatch_queue_t queue = Dispatch_get_global_queue (Dispatch_queue_priority_default,0); -Dispatch_after (Dispatch_time (Dispatch_time_now, (int64_t) (3* nsec_per_sec)), queue, ^{ $ $NSLog (@"delaythread2===%@", [Nsthread CurrentThread]); - }); - } the - /**Wuyi * Three methods implement deferred invocation, do not open multi-threading, execute in main thread the */ -- (void) Delay1 { Wu -[Nsthread Sleepfortimeinterval:3]; AboutNSLog (@"delay1=%@", [Nsthread CurrentThread]); $ } -- (void) Delay2 { - -[Self performselector: @selector (Download:) Withobject:@"http://333.jpg"Afterdelay:3]; A } +- (void) Delay3 { the -dispatch_queue_t queue =dispatch_get_main_queue (); $Dispatch_after (Dispatch_time (Dispatch_time_now, (int64_t) (3* nsec_per_sec)), queue, ^{ the theNSLog (@"delay3=%@", [Nsthread CurrentThread]); the the }); - in /*GCD: Equivalent to the above the Dispatch_after (Dispatch_time (Dispatch_time_now, (int64_t) (3 * nsec_per_sec)), Dispatch_get_main_queue (), ^{ the About NSLog (@ "delay3=%@", [Nsthread CurrentThread]); the the });*/ the + - theNSLog (@"delay====%@", [Nsthread CurrentThread]);Bayi } the the- (void) Download: (NSString *) URL { - -NSLog (@"delay2=%@", [Nsthread CurrentThread]); the } the the the @end
Deferred call -05-GCD