I am trying to return an array with my NSURLSession call.
I have the following method:
func wsQAshowTag(tag: Int) -> AnyObject
{
var tableArray = []
let requestString = NSString(format:"URL", tag) as String
let task = NSURLSession.sharedSession().dataTaskWithURL(NSURL(string: requestString)!, completionHandler: { (data, response, error) -> Void in
do{
tableArray = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.AllowFragments) as! NSArray
print(tableArray)
}
catch {
print(error)
}
})
task.resume()
return tableArray
}
When I call this method and try to print it, its empty. When I put breakpoints inside my method, I can see that tableArray is getting populated....why is it doing this and how do I fix it?
let wsQAshowTagArray = self.wsQAshowTag(38936)
print(wsQAshowTagArray)