Can someone explain dispatch_async() for me in this scenario

喜欢而已 提交于 2019-12-06 07:30:33

When creating a NSURLSession you can specify the delegate/completion queue. If you don't specify a queue

the session creates a serial operation queue for performing all delegate method calls and completion handler calls.

So this means that your callbacks are called on a private serial queue. Now, all UI must be updated on the main queue, this is why tableView.reloadData() wasn't working.

To remove the dispatch call to the main_queue create the session like this

let session = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration(), delegate: nil, delegateQueue: NSOperationQueue.mainQueue())
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!