Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"NSSet allObjects" does random ordering?

I have the following code:

self.temporaryImageArray = [(NSSet *)[[array objectAtIndex:0] images] allObjects]

Array holds an Band object from my CoreData model. It has an NSSet as a property called "images".

Now I use this temporaryImageArray to determine via timestamps whether or not the images need to be updated. I have come across some very random behavior and my question now is:

Does [NSSet allObjects] return the Objects from the Set randomly in no order?

Is there any way to prevent this or to have it return it in order? It would lessen the complexity of my code a lot.

like image 259
Octoshape Avatar asked Sep 09 '11 23:09

Octoshape


1 Answers

NSSet is an unordered collection. It has no idea what the "order" of its objects are. Therefore, when you call -allObjects, it returns them unordered.

Note that the documentation on -allObjects states:

An array containing the set’s members, or an empty array if the set has no members. The order of the objects in the array isn’t defined.

(emphasis mine)

like image 165
Lily Ballard Avatar answered Oct 11 '22 07:10

Lily Ballard