Search code examples
sortingios7nsmutablearraynsarraynssortdescriptor

NSArray Sorting Examples


Please anyone help me to find out the Sort elements of array which contains the names of students like:

NSArray *studentsNames=@[@"bill", @"rob", @"ady",@"jhon", @"robert", @"prince"];

All sorting function present in NSArray like following :

  1. sortedArrayHint
  2. sortedArrayUsingFunction:context
  3. sortedArrayUsingFunction:context:hint
  4. sortedArrayUsingDescriptors
  5. sortedArrayUsingSelector
  6. sortedArrayUsingComparator
  7. sortedArrayWithOptions:usingComparator

Please give me proper examples or link for this.


Solution

  • You can sort NSArray in following manner

    studentsNames = [anArray sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
    

    Hope this will help you.