var seconds = 10//countdown time Let queue = Dispatch_get_global_queue (dispatch_queue_priority_default, 0) Let timer = Dispatch_source_create (dispatch_source_type_timer, 0, 0,queue); Dispatch_source_set_timer (timer,dispatch_walltime (nil, 0), 1 * nsec_per_sec, 0); Execute Dispatch_source_set_event_handler per second (timer) {if (seconds<=0) {//Countdown end, Close dispatch _source_cancel (timer); Dispatch_async (Dispatch_get_main_queue (), {//SET interface button display according to your own needs set Btn.settitlecolor (U Icolor.blackcolor (), forstate:. Normal) Btn.settitle ("Get Verification Code", Forstate:.) Normal) Btn.titlelabel?. Font = defaultFont14 btn.userinteractionenabled = true}); }else{Dispatch_async (Dispatch_get_main_queue (), {uiview.beginanimation S (Nil, Context:nil) uiview.setanimationduration (1) }) Dispatch_async (Dispatch_get_main_queue (), {//Settings interface button display According to your own needs set Uiview.beginanimations (Nil, Context:nil) uiview.setanimationduration (1) btn.s Ettitlecolor (Uicolor.orangecolor (), forstate:. Normal) Btn.settitle ("\ (seconds) seconds after Resend", Forstate:. Normal) Btn.titlelabel?. Font = uifont.systemfontofsize (one) uiview.commitanimations () Btn.userinteractionenab LED = false}) seconds-= 1}} dispatch_resume (Time R
10 second timer. Organize your Memo
GCD Timer operation