I'm trying to write an HTTP request using Swift and I really only see people going one way or another (actually not so much GCD) to do HTTP requests on iOS.
If I want to make an HTTP request in iOS, what would be the best way to go about it: Use Grand Central Dispatch or write some closure block? Also, where can I find some great examples. From what I read online, I'm having a hard time seeing the benefits of one over the other.
At the moment, I have this code:
let priority = DISPATCH_QUEUE_PRIORITY_DEFAULT
dispatch_async(dispatch_get_global_queue(priority, 0), { ()->() in
self.activityIndicator.startAnimating()
self.authenticateUser()
dispatch_async(dispatch_get_main_queue(), {
self.activityIndicator.stopAnimating()
})
})
From what I see in the Debug Session tab for the Processor, I can see it jump from Thread X to Thread Y (for authenticateUser) and back to Thread X. Which is good - this is what I want (I'm sure).
Any good examples of GCD or Blocks/Closures written in Swift that you might be aware of would be very handy too. Thanks!