我必須用關鍵字「likecount」按降序排列這個數組。 我怎樣才能按特定鍵排序?本文是我的輸出,在控制檯來:幫助排序NSArray?
source id key is (
{
2 = likecount;
"This wall post is not from application. Direct from website." = message;
},
{
0 = likecount;
"New integration" = message;
},
{
1 = likecount;
"This is beta testing.. yes" = message;
},
{
2 = likecount;
"hello wall testing.." = message;
}
)
我想這下面的代碼,但沒有得到任何結果。仍然輸出沒有排序。
NSSortDescriptor *descriptor=[[NSSortDescriptor alloc]initWithKey:@"likecount" ascending:YES];
NSArray *sortdescriptor=[NSArray arrayWithObject:descriptor];
NSArray *sortedarray=[array sortedArrayUsingDescriptors:sortdescriptor];
NSLog(@"source sorting id key is %@",sortedarray);
NSLog(@"source [email protected]@@@@@ id key is %@",array);
//數組變量,它持有實際內容
什麼都ü嘗試? – vikingosegundo
我試過這個鏈接但沒有得到輸出。我可能是我的錯誤。 http://stackoverflow.com/questions/1844031/how-to-sort-nsmutablearray-using-sortedarrayusingdescriptors –