rodrigochousal rodrigochousal - 3 months ago 34
Swift Question

Create array from NSSet in order

I am trying to create an array from an existing

, but I can't find a method that creates the array in order. The only method I found was
, but this method returns an array without a specified order (random indexes). Any ideas?


Use allObjects to get unsorted array, then use descriptor to do the sort stuff. For example:

NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"type1.size" ascending:YES];
NSArray *finalArray = [self.firstArray sortedArrayUsingDescriptors:[NSArray arrayWithObjects:descriptor,nil]];