Last active
August 29, 2015 14:02
-
-
Save jbrjake/6f36fb64c4ffd19f35db to your computer and use it in GitHub Desktop.
Cleaner async with Swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Obj-C async calls | |
================= | |
Background queue | |
---------------- | |
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ | |
// Do stuff | |
}); | |
Main (UI) queue | |
--------------- | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
// Do stuff | |
}); | |
Swift async calls | |
================= | |
Create convenience functions | |
---------------------------- | |
func mainline(call:()->Void) {dispatch_async(dispatch_get_main_queue(), {call()})} | |
func async(call:()->Void) {dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {call()})} | |
Background queue | |
---------------- | |
async{ | |
// Do stuff | |
} | |
Main (UI) queue | |
--------------- | |
mainline{ | |
// Do stuff | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment