I have an NSDictionary where both the keys and values are NSStrings and I'd like to create one NSString from them in the form of
Key1: Value1
Key2: Value2
What is the best method of doing this?
I have an NSDictionary where both the keys and values are NSStrings and I'd like to create one NSString from them in the form of
Key1: Value1
Key2: Value2
What is the best method of doing this?
Lets assume your dictionary is called myDict
and key
is the value of the key you are looking for
[NSString stringWithFormat:@"%@: %@", key, [myDict objectForKey: key]];
This will return
Key: Value
Of course if this is just for you logging on the console you can make life easier for yourself and do something like
NSLog(@"%@", [myDict description]);
Edit::
To display the entire dictionary you can use a for each loop thusly:
NSMutableString *finalString = [NSMutableString string];
for(NSString *key in [myDict allKeys]){
[finalString appendFormat:@"%@: %@\n", key, [myDict objectForKey: key]];
}