Thursday, February 2, 2012

Sort NSArray - iPhone SDK


Sort array of NSNumber


NSSortDescriptor *highestToLowest = [NSSortDescriptor sortDescriptorWithKey:@"self" ascending:NO];
[mutableArrayOfNumbers sortUsingDescriptors:[NSArray arrayWithObject:highestToLowest]];


Sort array of NSDictionary


NSSortDescriptor *descriptor = [[[NSSortDescriptor alloc] initWithKey:@"product_name" ascending:YES] autorelease];
NSArray *descriptors = [NSArray arrayWithObjects:descriptor, nil];

NSArray *realArray = [arrayObject sortedArrayUsingDescriptors:descriptors];

No comments: