I have been having this error with my swift program, I am using PHP and MySQL as database. I am to display the data from database to tableview. it was working before but after a few times of running it to the emulator, I've been having the same error
class Home: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var btnaddclass: UIButton!
@IBOutlet var tableView: UITableView!
var values: NSArray = []
func get(){
let url = NSURL(string: "http://localhost/show_db.php")
let data = NSData(contentsOf: url! as URL)
values = try! JSONSerialization.jsonObject(with: data! as Data, options:JSONSerialization.ReadingOptions.mutableContainers)as! NSArray
tableView.reloadData()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return values.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! SpecialCell
let maindata = values[indexPath.row] as! [String:AnyObject]
cell.Lblclasstitle.text = maindata["class_title"] as? String
cell.Lblschool.text = maindata["school"] as? String
cell.Lblsubject.text = maindata["subject"] as? String
return cell
}
override func viewDidLoad() {
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
get()
}
override func viewWillAppear(_ animated: Bool) {
self.tableView.reloadData()
}
}