Swift 2016-06-22 23:27
Swift 后台执行代码封装库 Async
回复:0 查看:5384 感兴趣:11 赞:0
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
}
相关开源代码
EFIconFont: 一个用 Swift 实现的 IconFont 封装
Swift Zip文件压缩与解压框架
EFResume - 一个普通的 Swift 简历模板
Swift 优雅的定时器及执行工具库 Each
Swift 解析、格式化及验证国际电话号码工具库 PhoneNumberKit
Swift 版 FlatBuffers(跨平台序列化库)FlatBuffersSwift
Swift 编写的 Github API 客户端 Github.swift
Swift OAuth授权库 SwiftyOAuth
Swift 音频处理库 TempiFFT
iOS通知中心封装库SwiftNotificationCenter