iphone - objective-c 对 NSStrings 的 NSMutableSet 进行排序?

标签 iphone objective-c nsmutableset

<分区>

Possible Duplicate:
What is the most efficient way to sort an NSSet?

我目前有一个 NSMutableSet,其中包含以下字符串列表。例如。: {@"c",@"d",@"e",@"f",@"g",@"a"}

有人可以告诉我如何按字母顺序对这些值进行排序吗?有没有办法使用 sortedArrayUsingDescriptors: 来做到这一点?

最佳答案

当然,你可以使用那个方法:

NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"description" ascending:YES];
NSArray *sortedArray = [mySet sortedArrayUsingDescriptors:[NSArray arrayWithObject:sort]];

这只是创建了一个新的排序描述符,它指定了键“description”(NSString 提供了一个返回字符串的-description 方法)。然后它将包含该排序描述符的数组作为参数传递给 -sortedArrayUsingDescriptors:,您可以将其发送到任何 NSSet。

关于iphone - objective-c 对 NSStrings 的 NSMutableSet 进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8608862/

相关文章:

macos - 如何禁用 NSMutableSet 中所有对象的排序?

ios - UISplitViewController iPad 行为

iphone - 如何在ios中连续调用Web服务

ios - ios Appstore 中的下载量是如何计算的

ios - 创建后如何更改IBAction事件类型?

objective-c - 可变对象与不可变对象(immutable对象)的性能

objective-c - NSMutableSet不添加对象

ios - 与 UIView 子类相关的 UIView 元素显示在其容器之外

iOS 画外音 - 检测转子是否启用了垂直导航?

swift - 绘制路径有MKMapView问题