NSArray 排序示例

NSArray Sorting Examples

请任何人帮我找出包含学生姓名的数组的排序元素,例如:

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

NSArray 中的所有排序函数如下所示:

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

请给我适当的例子或link。

您可以按照以下方式对 NSArray 进行排序

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

希望对您有所帮助。