S Kumar S Kumar - 1 year ago 73
Swift Question

dispatch_async in Swift

I am really new to this programming language called


I use

dispatch_async(dispatch_get_main_queue(), ^{

this method for
in xcode 5.

I want implement it in swift language.

how do i implement dispatch queue in or swift?

Answer Source

You can use this syntax:

dispatch_async(dispatch_get_main_queue(), {

However, when the last argument is a block, Swift lets you put it outside the parentheses. This makes the function seem more like a control structure (like a for or if statement). Thus you can do this:

dispatch_async(dispatch_get_main_queue()) {