TommyG
TommyG

Reputation: 4155

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.

Upvotes: 7

Views: 672

Answers (2)

Arsalan Habib
Arsalan Habib

Reputation: 1395

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.

Upvotes: 1

ennuikiller
ennuikiller

Reputation: 46965

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.

Upvotes: 2

Related Questions