GCD timer Verification Code countdown, gcd timer Verification Code
-(IBAction) butClick :( UIButton *) but {dispatch_queue_t queue = queue (queue, 0); _ timer = dispatch_source_create (queue, 0, 0, queue); partition (_ timer, dispatch_walltime (NULL, 0), 1.0 * NSEC_PER_SEC, 0); _ block NSInteger time = count; dispatch_source_set_event_handler (_ timer, ^ {if (time <= 0) {dispatch_source_cancel (_ timer); dispatch_async (dispatch_get_main_queue (), ^ {[but setTitle: @ "re-obtain" forState: UIControlStateNormal];. userInteractionEnabled = YES;. alpha = 1.0;. backgroundColor = [UIColor whiteColor] ;});} else {NSString * strTime = [NSString stringWithFormat: @ "% lds", (long) time]; dispatch_async (dispatch_get_main_queue (), ^ {[but setTitle: strTime forState: UIControlStateNormal];. userInteractionEnabled = NO;. backgroundColor = [UIColor lightTextColor] ;}); time -- ;}}); dispatch_resume (_ timer );}