I copy the entire code first, and then go over it
class Regions: UITableViewController { let arr = ["ddd","sss"] override func viewDidLoad() { super.viewDidLoad() tableView.register(UITableViewCell.self, forCellReuseIdentifier: "myCell") ViewHelper.WaitingIndicator.indicatorStart(vc: self, view: view.self) Alamofire.request("http://app.com.ua/reference/regions").validate().responseJSON { response in switch response.result { case .success(let value): let json = JSON(value) let success = json["success"].stringValue print(success) var regions = [String]() var ids = [String]() for (_,subJson):(String, JSON) in json["data"] { let id = subJson["id"].stringValue let name = subJson["name"].stringValue regions.append(name) ids.append(id) } print(regions) print(ids) ViewHelper.WaitingIndicator.indicatorStop() case .failure(let error): print(error) ViewHelper.WaitingIndicator.indicatorStop() } } } override func numberOfSections(in tableView: UITableView) -> Int { return 1 } override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return arr.count } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "myCell", for: indexPath) cell.textLabel?.text = arr[indexPath.row] return cell } As you can see, for the test, I set the information from the topmost array of let arr = ["ddd","sss"] . -
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return arr.count } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "myCell", for: indexPath) cell.textLabel?.text = arr[indexPath.row] return cell } How to set information from the newly formed regions array from here
var regions = [String]() var ids = [String]() for (_,subJson):(String, JSON) in json["data"] { let id = subJson["id"].stringValue let name = subJson["name"].stringValue regions.append(name) ids.append(id) } That is, refer to it. When you create at the very top, in place of let arr = ["ddd","sss"] get an appeal to an empty, not yet filled with Json array, and in
`viewDidLoad()` you will not turn, and static too you will not make In general, I can not catch up with this elementary)
var arr = ["ddd","sss"]. In the query, makeself.arr = regionsandself.tableView.reloadData(). A list of regions received should be displayed. - VAndrJ