Iphone 具有范围对象的sort NSMutablearray

Iphone 具有范围对象的sort NSMutablearray,iphone,objective-c,ios,Iphone,Objective C,Ios,我已将范围对象添加到NSMutable数组,即[5,12}{0,4}{18,10}]。现在我想按递增顺序对这个NSMutable数组进行排序。我使用以下代码以递增的顺序获取NSMutable数组对象 NSArray *stringIndexes = [StringIndexes copy]; stringIndexes = [stringIndexes sortedArrayUsingSelector:@selector(compare:)]; N

我已将范围对象添加到NSMutable数组,即[5,12}{0,4}{18,10}]。现在我想按递增顺序对这个NSMutable数组进行排序。我使用以下代码以递增的顺序获取NSMutable数组对象

        NSArray *stringIndexes = [StringIndexes copy];
        stringIndexes = [stringIndexes sortedArrayUsingSelector:@selector(compare:)];
        NSLog(@"stringIndexes..:%@",stringIndexes);
但它没有提供所需的输出。如果有人知道如何对具有范围对象的NSMutable数组进行排序。请帮帮我


感谢大家。

如果要向数组添加范围,请使用

NSValue *value = [NSValue valueWithRange:(NSRange)range];
要对阵列进行排序时:

[myArray sortUsingComparator:^NSComparisonResult(NSValue *val1, NSValue *val2, BOOL *stop) {
  NSRange range1 = [val1 rangeValue];
  NSRange range2 = [val2 rangeValue];
  // you need to fine tune the test below - not sure what you want
  if(range1.location == range2.location) return NSOrderedSame;
  if(range1.location < range2.location) return NSOrderedAscending;
  if(range1.location > range2.location) return NSOrderedDescending;
  assert(!"Impossible");
  } ];
[myArray sortUsingComparator:^n比较结果(NSValue*val1,NSValue*val2,BOOL*stop){
NSRange range1=[val1 rangeValue];
NSRange range2=[val2 rangeValue];
//你需要微调下面的测试-不确定你想要什么
如果(range1.location==range2.location)返回OrderedName;
如果(range1.locationrange2.location)返回降级;
断言(!“不可能”);
} ];

如果要向数组添加范围,请使用

NSValue *value = [NSValue valueWithRange:(NSRange)range];
要对阵列进行排序时:

[myArray sortUsingComparator:^NSComparisonResult(NSValue *val1, NSValue *val2, BOOL *stop) {
  NSRange range1 = [val1 rangeValue];
  NSRange range2 = [val2 rangeValue];
  // you need to fine tune the test below - not sure what you want
  if(range1.location == range2.location) return NSOrderedSame;
  if(range1.location < range2.location) return NSOrderedAscending;
  if(range1.location > range2.location) return NSOrderedDescending;
  assert(!"Impossible");
  } ];
[myArray sortUsingComparator:^n比较结果(NSValue*val1,NSValue*val2,BOOL*stop){
NSRange range1=[val1 rangeValue];
NSRange range2=[val2 rangeValue];
//你需要微调下面的测试-不确定你想要什么
如果(range1.location==range2.location)返回OrderedName;
如果(range1.locationrange2.location)返回降级;
断言(!“不可能”);
} ];

您是如何将
NSRange
添加到可变数组的<代码>NSRange不是对象,而是结构。我已将NSRange添加到nsmutable数组中。NSRange不是Objective-C对象。。。如果您试图添加NSRange,请向错误显示“NSRange”类型的集合元素(也称为_NSRange)不是Objective-C对象。“我已将NSRange添加到可变数组中”-如何?向问题中添加一些代码!您可能应该将问题标题改为“如何对NSString数组进行排序”您如何将
NSRange
添加到可变数组中?
NSRange
不是对象,而是结构。我已将NSRange添加到可变数组中可变数组.NSRange不是Objective-C对象…如果您试图添加NSRange,请向错误显示“类型为“NSRange”(又名_NSRange)的集合元素不是Objective-C对象。”我已将NSRange添加到可变数组中-如何?为你的问题添加一些代码!您可能应该将问题标题改为“如何对NSString数组排序”