[Code notes] iOS-sorts arrays and notes ios-sorts Arrays
I. Code.
-(Void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. // directly sort the object NSSortDescriptor * descriptor = [NSSortDescriptor attributes: nil ascending: YES]; NSArray * descriptors = [NSArray attributes: descriptor]; NSArray * myDataArray = [NSArray attributes: @ "what", @ "xero", @ "highlivity", @ "mountain", @ "Vicente", @ "Balance", nil]; NSLog (@ "--- myDataArray --- % @", myDataArray); NSArray * resultArray = [myDataArray sortedArrayUsingDescriptors: descriptors]; NSLog (@ "% @", resultArray ); // NSArray uses sortedArrayUsingDescriptors to return the sorted array. // NSMutableArray can directly use sortUsingDescriptors to sort the array itself. }
2. output.
11:56:45. 178 sort arrays [6739: 168615] (Balance, Vicente, highlivity, mountain, what, xero)