I'm trying to fill a UITableView
with data that I acquire via a DataTaskWithURL
call. However, the tableview has loaded before the completion handler has started.
I searched for this problem and found things about moving it to the main thread but that didn't seemed to work. Any idea on how I can move it to the right que before the tableview had loaded?
My code:
var jsonData: JSON = []
func getRequestForTableView() {
let urlPath = "[URL]"
let url: NSURL = NSURL(string: urlPath)!
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithURL(url, completionHandler: {data, response, error -> Void in
let json = JSON(data: data)
println(json.count)
self.jsonData = json
})
task.resume()
}