I have async request to HTTP, i want to read JSON and fill my viewtable.
I get data with request, i make NSArray, but i can pass it inside my functions, tableView number
You need to call reloadData()
method after json data is downloaded:
class ThirdView: UITableViewController {
var jsonz: NSArray = ["Ray Wenderlich"]
let url = NSURL(string: "http://iweddings.ru/xmlrestaurant.json")
override func viewDidLoad() {
super.viewDidLoad()
let task = NSURLSession.sharedSession().dataTaskWithURL(url!) {(data, response, error) in
let json = NSJSONSerialization.JSONObjectWithData(data!, options: nil, error: nil) as! NSArray
println(json)
self.jsonz = json;
self.tableView.reloadData()
}
task.resume()
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1;
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
println(self.jsonz.count);
return self.jsonz.count;
}
}