You can use filter method of array:
//this filter will return you all objects whose group type is equal to 1
let collectionArray = (product_groups?.filter({$0.group_type == 1}))
//this filter will return you all objects whose group type is equal to 2
let tableArray = (product_groups?.filter({$0.group_type == 2}))
For group title to be section header:
- (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return tableArray[section].group_title
}
For products to display in each cell:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//cell code...
cell.titleLabel.text = tableArray[indexPath.section][indexpPath.row].product_name
// cell code
}
12
solved Populate CollectionView and TableView using objects at different index of same array [closed]