I have a multidimensional array
var sectionArray = [ ["sectionName":"Time","sectionData":[["fname":"true detective","date":"may 20"],["fname":"abbas","date":"may 10"]],"expanaded":false],["sectionName":"Message","sectionData":[["movie":"true","event":"Bring food"]]
from this array I have to get fname keys value where fname is the value of the key sectionData.how will I achieve
that? I have to populate this data on tableview
my cellForRowAt
switch (indexPath.section) {
case 0:
if let cell1 = tableview.dequeueReusableCell(withIdentifier: "DetailedTableViewCell", for: indexPath) as? DetailedTableViewCell{
let c = indexPath.section
cell1.timeCardTitle.text = sectionArray[c]["sectionName"][c]["fname"] as? String
return cell1
}
2
Answers
the array will be
It’s easier if you make structured data from your unstructured dictionary representation:
Now you can implement the table view data source’s number of sections as
arranged.count
, and number of rows in sections asarranged[indexPath.section].count
and configure your cell for any particular row by getting the row model usingarranged[indexPath.section].rows[indexPath.row]
and then using it to configure a cell.Actually I notice you have two types of rows, so things will be much easier if you can get your data in this form: (Either write it directly in code like shown, or if you have to, map it from the unstructured array /dictionary representation a bit like as shown above)
When making a cell for cellForRowAtIndexPath, you can switch on the row type and then dequeue and configure reusable cell for the correct type.