我有NSarray
包含動物列表。該數組包含具有重複元素的動物列表。我必須在數組中創建一個具有不同值的數組。 應使用NSPredicate
刪除重複的值。如何使用NSPredicate對NSStrings的NSArray進行排序?
這裏是我的代碼: -
NSArray *arrAnimals = [[NSArray alloc] initWithObjects:@"Cat",@"Rat",@"Fish",@"Cat",@"Fish",@"Cat",@"Cat",@"Bird",@"Fish",@"Cat",@"Frog", nil];
NSPredicate *predicate = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"distinct"]];
arrAnimals = [arrAnimals filteredArrayUsingPredicate:predicate];
這裏我使用排序的數組「獨特」的關鍵字,但沒能找到任何解決方案。 我更喜歡很多鏈接。
請解決我的問題。
是您的目標,以消除重複,還是按字母順序排序?或兩者? –
http://stackoverflow.com/questions/1351182/how-to-sort-a-nsarray-alphabetically – Yogendra
Yaah我的目標是刪除重複的條目和按字母順序排序。 – Apoorv