Попробуйте сделать это:
//replace
let jsonData:NSArray = NSJSONSerialization.JSONObjectWithData(data!, options:NSJSONReadingOptions.MutableContainers , error: &err) as? NSArray
//with
let json = try! NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions())
, а затем распечатать (JSON), чтобы увидеть, какой тип объекта вы получаете назад
Вот код, я использую, чтобы сделать запрос получите:
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 ответ о создании запросов
И вот простой метод cellForRowAtIndexPath, который заполняет tableViewCells из массива:
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
}
С этим self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
в viewDidLoad