I'm displaying a dictionary as UITableView. I did this very easily in Objective- c . But now in swift, I cannot get values from array of dictionary. When I try to get values in the tableView:cellForRowAtIndexPath the precompiler throw error like
Cannot convert value of type "AnyObject?!" to specified type 'Array'
or like in this example below
Cannot convert value of type "AnyObject?!" with an idnex of type 'int'
var cellArray = []
override func viewDidLoad() {
cellArray = [
[
"section" : "Melody",
"rows" :
[
[
"title" : "Wi-Fi / Pairing",
"icon" : "",
"action" : "actionConnectSpeaker"
],
[
"title" : "Sound",
"icon" : "",
"action" : "actionConnectSpeaker"
]
]
],
[
"section" : "Music",
"rows" :
[
[
"title" : "Add a new account",
"icon" : "",
"action" : "actionAddAccount"
]
]
]
]
}
...
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: UITableViewCellStyle.Value2, reuseIdentifier: nil)
cell.textLabel?.text = cellArray[indexPath.section]["rows"][indexPath.row]["title"]
return cell
}
I conclude we cannot do like this... I find any example. I probably not understand something about Types in Swift ...