rodrigochousal rodrigochousal - 1 year ago 161
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?

Answer Source

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]];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download