I must be under some strange misconception ...
Consider:
NSSet * mySet = [NSSet setWithArray:@[@1, @9, @3]] ;
NSOrderedSet * mySortedSet = [NSOrderedSet orderedSetWithSet:mySet] ;
for (NSNumber * n in mySet) {
NSLog(@"unsorted: %@", n) ;
}
for (NSNumber * n in mySortedSet) {
NSLog(@"--sorted: %@", n) ;
}
And the console log:
2014-05-05 20:38:46.645 WoGa[50557:60b] unsorted: 9
2014-05-05 20:38:48.675 WoGa[50557:60b] unsorted: 1
2014-05-05 20:38:49.875 WoGa[50557:60b] unsorted: 3
2014-05-05 20:38:54.277 WoGa[50557:60b] --sorted: 9
2014-05-05 20:38:55.544 WoGa[50557:60b] --sorted: 1
2014-05-05 20:38:56.684 WoGa[50557:60b] --sorted: 3
Huh? How is that 'ordered' ? I have no problem sorting myself if needs be, but what exactly is an NSOrderedSet then?
I can accept that the order of the elements in mySet
is unpredictable.
But what is [NSOrderedSet orderedSetWithSet:mySet]
supposed to achieve if not sorting in some order or other ?
From the documentation:
You can use ordered sets as an alternative to arrays when the order of elements is important and performance in testing whether an object is contained in the set is a consideration—testing for membership of an array is slower than testing for membership of a set.
Again, what is the order that NSOrderedSet orderedSetWithSet:
is supposed to provide you with?