2010-08-27 11 views

cevap

109

Anahtarları sıralamak ve daha sonra üzerlerine yineleme tarafından NSMutableArray oluşturabilirsiniz.

NSArray *sortedKeys = [[dict allKeys] sortedArrayUsingSelector: @selector(compare:)]; 
NSMutableArray *sortedValues = [NSMutableArray array]; 
for (NSString *key in sortedKeys) 
    [sortedValues addObject: [dict objectForKey: key]]; 
+6

Cevabınızı cevabımda http://stackoverflow.com/a/13406407/257533 –

+4

için kullandım. Bu doğru bir cevap mı, değil mi? oy çok var, ama kabul etmiyor musunuz? –

+0

Doğru cevap budur. Ne yazık ki, kolay bir yöntem (iOS 7'de) [Sözlük keysSortedByValueUsingSelector: @selector (karşılaştırın :)] 'çalışmıyor. Bir sebepten ötürü, neredeyse sırayla rastgele sonuçlar veriyor. 'KeysSortedByValueUsingSelector:' dizinin son değerine dayanarak diziye eklendiği bir şey yapıp yapmadığını merak ediyorum. – mikeho

-1

Cevabın size doğru bilgi vermek muydunuz

NSDictionary *yourDictionary; 
NSArray *sortedKeys = [yourDictionary.allKeys sortedArrayUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"self" ascending:YES]]]; 
// As we using same keys from dictionary, we can put any non-nil value for the notFoundMarker, because it will never used 
NSArray *sortedValues = [yourDictionary objectsForKeys:sortedKeys notFoundMarker:@""]; 
İlgili konular