0
contaning字典我有一個包含字典像下面陣列: -排序的NSMutableArray在alphnumberic方式
(
{
"act_priority" = B1;
}
{
"act_priority" = "";
}
{
"act_priority" = A;
}
{
"act_priority" = A3;
}
{
"act_priority" = B;
}
{
"act_priority" = A2;
}
{
"act_priority" = A1;
}
{
"act_priority" = "";
}
)
我想按字母順序排序在和數字兩種方式: -
(
{
"act_priority" = A1;
}
{
"act_priority" = A2;
}
{
"act_priority" = A3;
}
{
"act_priority" = B1;
}
{
"act_priority" = A;
}
{
"act_priority" = B;
}
{
"act_priority" = "";
}
{
"act_priority" = "";
}
)
我曾試圖低於: -
NSArray* sorted = [activityArray sortedArrayUsingComparator:(NSComparator)^(NSDictionary *item1, NSDictionary *item2) {
NSString *score1 = [item1 objectForKey:@"act_priority"];
NSString *score2 = [item2 objectForKey:@"act_priority"];
return [score1 compare:score2 options:NSNumericSearch];
}];
另外: -
NSSortDescriptor *Sorter = [[NSSortDescriptor alloc] initWithKey:@"act_priority" ascending:YES];
[activityArray sortUsingDescriptors:[NSArray arrayWithObject:Sorter]];
,但它給我像
(
{
"act_priority" = "";
}
{
"act_priority" = "";
}
{
"act_priority" = A;
}
{
"act_priority" = B;
}
{
"act_priority" = A1;
}
{
"act_priority" = A2;
}
{
"act_priority" = A3;
}
{
"act_priority" = B1;
}
)
請幫助
在你的塊,檢查字符串的長度(@ 「」),然後返回足夠NSCompareResult (最後用「@」表示)。爲什麼「NSNumericSearch」? – Larme 2015-02-09 12:56:20
@Larme感謝您的快速回復。你能爲我輸入代碼嗎?數字意味着像A1,A2,B1,B2,A,B,「」,「」我喜歡這樣的序列 – 2015-02-09 13:01:22
數字搜索實際上意味着你收到的輸出。如果你想要一個不同的搜索,你將不得不明確定義塊中的規則,而不是使用內置的「比較」。 – 2015-02-09 13:05:28