你的位置:首页 > 软件开发 > 操作系统 > Swift 延迟运行

Swift 延迟运行

发布时间:2016-07-22 10:00:07
//// DelayRun.swift// //// Created by XuQing on 16/7/1.// Copyright © 2016年 xuqing. All rights reserved.//import Foundationtypealias Ta ...
//// DelayRun.swift// //// Created by XuQing on 16/7/1.// Copyright © 2016年 xuqing. All rights reserved.//import Foundationtypealias Task = (cancel : Bool) -> ()func DelayRun(time:NSTimeInterval, task:()->()) -> Task? {    func dispatch_later(block:()->()) {    dispatch_after(      dispatch_time(        DISPATCH_TIME_NOW,        Int64(time * Double(NSEC_PER_SEC))),      dispatch_get_main_queue(),      block)  }    var closure: dispatch_block_t? = task  var result: Task?    let delayedClosure: Task = {    cancel in    if let internalClosure = closure {      if (cancel == false) {        dispatch_async(dispatch_get_main_queue(), internalClosure);      }    }    closure = nil    result = nil  }    result = delayedClosure    dispatch_later {    if let delayedClosure = result {      delayedClosure(cancel: false)    }  }    return result;}func cancel(task:Task?) {  task?(cancel: true)}

原标题:Swift 延迟运行

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录