I have a plist that I copied into my project to use it in a TableView. The plist loads and I verified by printing the contents and number of rows to the console. When I build the project, I get a blank TableView with no data though. I've searched and tried for days, but still can't get it to display. Here is my code:
import UIKit
class TableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
let filePath = Bundle.main.path(forResource: "directory", ofType: "plist")
let employees = NSArray(contentsOfFile: filePath!) as! [[String: String]]
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return (employees.count)
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TableViewControllerTableViewCell
cell.nameLabel.text = (employees[indexPath.row]["Name"]) //as! String)
cell.positionLabel.text = (employees[indexPath.row]["Position"]) //as! String)
return cell
}
for item in employees {
print(item["Name"] as Any)
print(item.count)
print(employees.count)
}
And here is some of the plist:
<plist version="1.0">
<array>
<dict>
<key>Department</key>
<string>Operations</string>
<key>Position</key>
<string>Operator </string>
<key>Name</key>
<string>John Smith</string>
<key>Email</key>
<string>john.smith@nospam.net</string>
<key>Cell Phone</key>
<string>123-456-7890</string>
<key>Office Phone</key>
<string></string>
</dict>
<dict>
<key>Department</key>
<string>Sales</string>
<key>Position</key>
<string>Salesperson</string>
<key>Name</key>
<string>Susan Brown</string>
<key>Email</key>
<string>susan.brown@nospam.net</string>
<key>Cell Phone</key>
<string>234-567-8901</string>
<key>Office Phone</key>
<string>345-678-9012</string>
</dict>
And here is the other swift file the code references:
import UIKit
class TableViewControllerTableViewCell: UITableViewCell {
@IBOutlet var nameLabel: UILabel!
@IBOutlet var positionLabel: UILabel!
Thanks in advance! Seriously pulling hair out....