因此,我有一對NSMutableDictionarys,每個特定字典的鍵/值對保持一個字符串或整數值。我想知道是否有方法遍歷字典並連接值。在PHP中我可以用一個陣列連接NSMutableDictionary轉換爲int,NSInteger和NSString的所有值
// either the dictionary holds all integers or all string values
$integer_array = array('a' => 2, 'b' => 9, 'c' => 2, 'd' => 0, 'e' => 1);
foreach($integer_array as $key => $value) {
$concatenated_value .= $value;
}
// cast to int
$concatenated_value = (int) $concatenated_value;
// prints: 29201
echo $concatenated_value;
我也可以使用implode()以及
$concatenated_value = (int)(implode("", $integer_array));
// prints: 29201
echo $concatenated_value;
是有這樣的事情適用於iOS的Objective-C做這樣的事情?
'NSDictionary'在Objective C不被排序,因此級聯將是隨機的,除非你進行排序鍵,然後在一個循環串聯值。 – dasblinkenlight 2012-07-20 01:40:08
是的,循環內排序是我在想什麼 – 2012-07-20 01:45:15