Skip to content

Instantly share code, notes, and snippets.

@jbrjake
Last active August 29, 2015 14:02
Show Gist options
  • Save jbrjake/6f36fb64c4ffd19f35db to your computer and use it in GitHub Desktop.
Save jbrjake/6f36fb64c4ffd19f35db to your computer and use it in GitHub Desktop.
Cleaner async with Swift
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