Search code examples
iphoneobjective-cxcodensarray

How to reorder elements (NSString) of an NSArray alphabetically?


How to reorder elements (NSString) of an NSArray alphabetically?


Solution

  • you can use sortDescriptor

     NSSortDescriptor *descriptor = [[[NSSortDescriptor alloc] initWithKey:@"yourKey" ascending:YES selector:@selector(caseInsensitiveCompare:)] autorelease];
    NSArray * sortedArray =
        [yourArray sortedArrayUsingDescriptors:descriptor];