Try doing this:
//replace
let jsonData:NSArray = NSJSONSerialization.JSONObjectWithData(data!, options:NSJSONReadingOptions.MutableContainers , error: &err) as? NSArray
//with
let json = try! NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions())
and then print(json) to see what kind of object you're getting back
Here's some code I use to make a get request:
let url = NSURL(string: urlString)
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithURL(url!, completionHandler:{
(data, response, error) in
if error != nil {
//Handle error, just for testing I do this:
print(error!.localizedDescription)
} else {
let json = try! NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions())
print(json)
//use data from json, if it's a dictionary, you can loop through and add objects to an array
}
})
task!.resume()
Here's an answer about making requests
And here's a simple cellForRowAtIndexPath method, which fills tableViewCells from an array:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCellWithIdentifier("cell")
let text = self.tableContents[indexPath.row] as! String
//tableContents is just the array from which you're getting what's going in your tableView, and should be declared outside of your methods
cell.textLabel?.text = text
return cell
}
With this self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
in viewDidLoad