Async code in Swift
Async code was never so easy
var image: UIImage!
Async.background {
// Do long running tasks here
let url = NSURL(string: "http://lorempixel.com/400/400/")
image = UIImage(data: NSData(contentsOfURL: url))
}.main {
// update UI
println("back to main thread")
self.view.addSubview(UIImageView(image: image))
}
let longWork = Async.background {
//work
}
//Other work. descided to cancel
longWork.cancel()
//Start with delay
Async.main(after: 2) {
//Move to next screen
}
- chain block
- set delay
- blocks are cancelable
Get lib here.
https://github.com/duemunk/Async
Written by Kostiantyn
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ios
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#