2013-03-30 34 views
0

我有一個NSMutableArray一些的NSNumber:每個項目的許多發生怎樣出現在一個的NSMutableArray

{1, 2, 3, 3, 2, 1, 6, 2} 

我想知道每個號碼的許多發生怎樣出現在列表中。

Ex : 
1 = 2 
2 = 3 
3 = 2 
6 = 1 
+2

您需要向我們展示您所嘗試過的以及它爲什麼不起作用。簡單地問「我需要」,「給我」不是這個網站的意思。 – Ares

回答

12

您可以將所有項目放入NSCountedSet

NSCountedSet* countedSet = [[NSCountedSet alloc] initWithArray:array]; 

for (NSNumber* number in countedSet) { 
    NSLog(@"%@ = %u", number, [countedSet countForObject:number]); 
} 
+0

我不知道NSCountedSet。這非常有用。 – cmii

+0

@cmi:你應該從你以前的問題的答案中知道它http://stackoverflow.com/questions/15709494/compare-two-arrays-with-the-same-value-but-with-a-different-order :-) –

相關問題