so I have a couple NSMutableDictionarys and each key/valeu pair for a specific dictionary hold either a string or integer value. I would like to know if there is a way to iterate through the dictionary and concatenate the values. In PHP I could do something like this using an array
// 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;
I could also use the implode() as well
$concatenated_value = ( int )(implode("", $integer_array));
// prints: 29201
echo $concatenated_value;
is there something like this for iOS Objective-C?
I don’t believe there is a predefined function for it. To me, this doesn’t seem like a very common thing to do (is it common in PHP?). I suppose the code would look like this in theory:
However, this is very unlikely to produce the results you want since dictionaries are not ordered. I think you need a different data structure or an array holding the keys in the order you inserted them (but at that point you might as well just use an array).
EDIT Since you are using an ordered array of keys, I edited the answer above.