0

I am trying to figure out on Google, but I cannot find "How to execute a method in background in Swift".

Is there something similar to

performsSelectorInBackground:

from Objective-C?

Thanks in advance!

ppalancica
  • 4,236
  • 4
  • 27
  • 42

2 Answers2

2

Because Swift is statically typed, there actually aren't selectors you can call.

What you should be doing instead is Grand Central Dispatch (GCD):

dispatch_async(dispatch_get_main_queue()) {
     // do your stuff here
}
Community
  • 1
  • 1
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
0

Both NSOperation and Grand Central Dispatch (GCD) are available in Swift. I would start by reading Apple's GCD and NSOperationQueue documentation:

https://developer.apple.com/LIBRARY/ios/documentation/Performance/Reference/GCD_libdispatch_Ref/index.html

https://developer.apple.com/library/ios/documentation/cocoa/reference/NSOperationQueue_class/index.html