Search code examples
iphonecore-datauitableviewnsset

Will [NSSet allObjects] return an array with the same order each time?


I have a list of custom objects being returned from a .NET WebService and am storing them using a To-Many relationship from the parent enitity with Core Data.

I want to use the NSSet as the datasource for a UITableView and push a new controller onto the stack when a row is selected.

When using [NSSet allObjects] does the array returned always have the same order? (I guess not as sets are unordered)

If not, how then can I use NSArray *myArray = [mySet allObjects]; in cellForRowAtIndexPath to get the name for the textLabel of the cell and then again in didSelectRowAtIndexPath to assign the object to the ViewController about to be pushed?

I already have the parent object synthesized in my UITableViewDelegate. I have thought about also having an NSArray synthesized and using allObjects only once in viewDidLoad to create but this is duplicating the data in memory


Solution

  • Your solution, extracting an NSArray once during viewDidLoad, is the correct one. You actually won't be duplicating much memory. Your objects will still only be in memory once; it's just that your NSSet and NSArray will both contain pointers to those objects.