欢迎加入QQ讨论群258996829

Swift 后台执行代码封装库 Async

发布时间:2016-06-22 23:27  回复:0  查看:4984  感兴趣:11  赞:0   最后回复:2016-06-22 23:27  

Swift 后台执行代码封装库 Async。

Swift 中写GDC(Grand Central Dispatch)类似这样的:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), {
    print("This is run on the background queue")

    dispatch_async(dispatch_get_main_queue(), {
        print("This is run on the main queue, after the previous block")
    })
})
使用  Async 的要简洁的多:

Async.background {
    print("This is run on the background queue")
}.main {
    print("This is run on the main queue, after the previous block")
}
Async支持的方法:

Async.main {}
Async.userInteractive {}
Async.userInitiated {}
Async.utility {}
Async.background {}
支持多个代码块:

Async.userInitiated {
    // 1
}.main {
    // 2
}.background {
    // 3
}.main {
    // 4
}


相关开源代码

您还未登录,请先登录

热门帖子

最新帖子