本文介绍了如何按数组计数对NSArray的嵌套NSArray进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含嵌套NSArrays的NSArray。我正在寻找一种方法来按照嵌套数组的对象数按升序对父数组进行排序。所以,如果 [array1 count]
为4, [array2 count]
为2且 [array3 count]
是9,我会得到:array2,array1,array3 ......
I have an NSArray that contains nested NSArrays. Im looking for a way to sort the parent array according to the object count of the nested arrays in ascending order. so if [array1 count]
is 4, [array2 count]
is 2 and [array3 count]
is 9, i would get : array2, array1, array3...
推荐答案
那里是一些解决方案,其中之一是:
There are a few solutions, one of which is:
NSSortDescriptor *sd = [NSSortDescriptor sortDescriptorWithKey:@"@count"
ascending:YES];
NSArray *sds = [NSArray arrayWithObject:sd];
NSArray *sortedArray = [array sortedArrayUsingDescriptors:sds];
这篇关于如何按数组计数对NSArray的嵌套NSArray进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!