Search code examples
iphoneobjective-cxcodensmutablearraynsarray

sorting mutable array in alphabetical order


I am having a nsmutable array and in that nearly 50 -60 object having different names ,and can i sort this array in alphabetical order (Is it possible, How?)


Solution

  • For a simple sort like this, I like to use sort descriptors.

    Suppose you have an mutable array of objects whose class has a name NSString property:

    NSSortDescriptor *sort=[NSSortDescriptor sortDescriptorWithKey:@"name" ascending:NO];
    [myArray sortUsingDescriptors:[NSArray arrayWithObject:sort]];