【问题标题】:sorting an array of NSObject based on one value based on one value within one object基于一个值对一个 NSObject 数组进行排序,该值基于一个对象内的一个值
【发布时间】:2013-11-20 09:02:56
【问题描述】:

我创建了一个对象,它看起来像这样

aOffice.branchname 
aOffice.lat
aOffice.lng
aOffice.distance

然后将其添加到可变数组(近分支)。 稍后我计算出每个对象到当前 gps 位置的距离,并将其添加到对象中并将其放回数组中。 (aOffice.distance)

我现在需要根据 aOffice.distance 的值对该数组进行排序,但不知道该怎么做

有人可以帮帮我吗

谢谢

【问题讨论】:

标签: ios iphone objective-c nsarray nsobject


【解决方案1】:
NSArray *sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"distance" ascending:NO]];
NSArray *sortedArray = [yourArray sortedArrayUsingDescriptors:sortDescriptors];

【讨论】:

  • 这是完美的,它有效。我不知道它是怎么做的,但现在我会调查一下
猜你喜欢
  • 1970-01-01
  • 2014-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-06-10
  • 2015-10-22
  • 2016-06-28
  • 2023-03-09
相关资源
最近更新 更多