我想知道是否可以在保持NSMutableArray (而不是NSArray)的同时对NSMutableArray进行排序。要么创建一个新的排序数组,要么重用同一个数组就可以了。
-编辑-编辑
谢谢你所有的回答。
[unsortedList sortUsingSelector:@selector(compareStage:)]; 对unsortedList排序。
我对sorted*Array*UsingSelector.很困惑
发布于 2013-11-04 16:20:54
您可以使用这些方法对原始NSMutableArray本身进行排序。
- (void)sortUsingFunction:(NSInteger (*)(id, id, void *))compare context:(void *)context;
- (void)sortUsingSelector:(SEL)comparator;
- (void)sortUsingComparator:(NSComparator)cmptr NS_AVAILABLE(10_6, 4_0);
- (void)sortWithOptions:(NSSortOptions)opts usingComparator:(NSComparator)cmptr NS_AVAILABLE(10_6, 4_0);
- (void)sortUsingDescriptors:(NSArray *)sortDescriptors; // NSSortDescriptorSorting发布于 2013-11-04 16:10:09
使用以下代码:
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"someKey" ascending:YES];
NSMutableArray *sortedArray = [[unsortedMutableArray sortedArrayUsingDescriptors:@[sortDescriptor]] mutableCopy];https://stackoverflow.com/questions/19771839
复制相似问题