I am confused as I am defining content of rows in a table view by a dictionary, but when ever I try to add it, it shows me an error.
var places = [[String: Any]]()
class TableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
if places.count == 0 {
places.append(["name":"Taj Mahal", "lat": "27.175277", "lon": "78.042128"])
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
cell.textLabel?.text = places[indexPath.row]["name"]
return cell
}
the error is in the part where I define:
cell.textlabel?.text = places[indexPath.row]["name"]
It should be:
As the type is
Any
and you need to specify it asString
, sincelabel
expectsString
s.