This may be a few questions bundled into one, but here is the situation. I am working in objective c, and have a for loop that’s going through an array of dictionary objects… like so.
for (NSDictionary *dictionary in array){
log(@"the dictionary object looks like this \n%@\n",dictionary);
log(@"value of someProp in the current dict object is %@",[dictionary valueForKey:@"someProp"]);
}
well that’s all nice and dandy but I want to tidy up how it prints out to the console a little bit. I am new to objective c, but experienced in other languages. I want to do something like this in objective c (wrote it in actionscript for an example)
var outputString:String;
for (items in dictionary){
outputString += dictionary.toString();
outputString += "value of item in current dict object is " + dictionary [item];// etc
}
// now just print out the contents of outputString;
trace(outputString);
the challenge I have here is collating the objects that are not of type string or NSString..
I know stuff like
NSString *outputString = @"";
for (//same loop as above in obj-c){
outputString = [outputString stringByAppendingString:**someString**];
}
but maybe I am just unfamiliar with the appropriate string method, because simply substituting dictionary to print out the whole dictionary object where it reads someString will produce an error because of course a dictionary object is not a string.
So I would like to
-accumulate the contents of what I would like to NSLog out in a series of strings summing it all up
-this includes the printing out the contents of dictionary objects (or maybe array objects too) converting it to a string, and adding it to outputString.
Anyone have any advice on how to go about doing this?
Try using [NSString stringWithFormat:@”Something about value: %@”, dictionaryItem]