override func viewDidLoad() { super.viewDidLoad() let xibfile = UINib(nibName: "mycell", bundle: nil) self.tableView.register(xibfile, forCellReuseIdentifier: "mikkihiiri") } override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return dummyData.count } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let secondCell = tableView.dequeueReusableCell(withIdentifier: "mikkihiiri")! secondCell.textLabel?.text = "\(dummyData[indexPath.row].lat) - \(dummyData[indexPath.row].lon)" return secondCell } override func viewDidAppear(_ animated: Bool) { self.fetch(url: "https://pohjus-rest-location.herokuapp.com/locations") } func parse(data: Data?) { if let d = data { let jsonDecoder = JSONDecoder() do { let stuff = try jsonDecoder.decode(Array<Location>.self, from: d) self.dummyData = stuff DispatchQueue.main.async { self.tableView.reloadData() } } catch let error { print(error) } } } func fetch(url: String) { let myURL = URL(string: url)! let httpTask = URLSession.shared.dataTask(with: myURL) { (optionalData, response, error) in self.parse(data: optionalData) } httpTask.resume() } }