Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

data structure best practices for UITableView datasource

I am trying to figure out whats the best data structure to hold the data source for a UITableView. I am looking for something as robust as possible - a structure that will hold data for the different sections, and which will enable convenient add and remove of objects. I saw a few implementations using NSMutableArrays and dictionaries, but I am still not convinced as to which approach is the most robust.

Appreciate your help and thoughts.

like image 785
TommyG Avatar asked Aug 29 '11 21:08

TommyG


2 Answers

NSMutableArray is the most efficient since the index path for row and section readily convert to integers which can be used to access the array elements.

like image 125
ennuikiller Avatar answered Oct 17 '22 15:10

ennuikiller


Depends on really how complex your data is. If its just couple of strings then an Array of NSStrings will suffice. If its like an image path, a text label and its description then maybe an array of custom class holding that data. I almost always go for the Arrays since you can get your desired object from it with the objectAtIndex:indexPath.row bit.

like image 1
Arsalan Habib Avatar answered Oct 17 '22 15:10

Arsalan Habib