I'm having trouble loading the items on a property list. Note my plist:
Here'smyfirstViewController:
importUIKitclassPage1:UITableViewController{varfilePath:String?varemployees:[[String:Any]]=[]overridefuncviewDidLoad(){super.viewDidLoad()self.tableView.delegate=selfself.tableView.dataSource=selffilePath=Bundle.main.path(forResource:"directory", ofType: "plist")
employees = NSArray(contentsOfFile: filePath!) as! [[String: Any]]
for item in employees {
print(item["Name"] as Any)
print(item.count)
print(employees.count)
}
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return employees.count
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let destination = segue.destination as? Page2,
let indexPath = tableView.indexPathForSelectedRow {
destination.itemSelecionado = employees[indexPath.row]
tableView .deselectRow(at: indexPath, animated: true)
}
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TableViewCell
cell.nameLabel.text = (employees[indexPath.row]["Name"] as! String)
cell.positionLabel.text = (employees[indexPath.row]["Position"] as! String)
return cell
}
}
Here's my second View Controller:
import UIKit
class Page2: UITableViewController {
var itemSelecionado: [Page1] = []
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.delegate = self
self.tableView.dataSource = self
}
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return itemSelecionado.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TableViewCell2
cell.emailLabel.text = (itemSelecionado.employees[indexPath.row]["Email"] as! String )
cell.phoneLabel.text = (itemSelecionado.employees[indexPath.row]["Phone"] as! String? )
return cell
}
}
Xcode is returning me 3 errors, they are:
However,Idonotunderstandthereasonfortheseerrors,couldanyonehelpme?
Thanksinadvance!
Problemtryingtoinsertimage: