I have a NSMutableDictionary holding EXIF metadata from a picture.
An example:
const CFStringRef kCGImagePropertyExifExposureTime;
Instead of accessing every key individually, I just want write the whole dictionary content into a label.
When I want to write this data into the console I would just use:
NSLog(@"EXIF Dic Properties: %@",EXIFDictionary );
That works fine, but if I use:
NSString *EXIFString = [NSString stringWithFormat:(@"EXIF Properties: %@", EXIFDictionary)];
I get warnings that the result is not a string literally and if I try to use that string to set my label.text, the program crashes.
Any idea where my error is?
[NSString stringWithFormat:(@"EXIF Properties: %@", EXIFDictionary)]is not, as you may think, a method with two arguments. It’s a method with one argument. That one argument is(@"EXIF Properties: %@", EXIFDictionary), which uses the comma operator and ends up returningEXIFDictionary. So in essence you havewhich is obviously wrong. This is also why you’re getting a warning. That warning tells you that the format argument is not a string literal, because using variables as format strings is a common source of bugs. But more importantly here, that argument isn’t even a string at all, and so it crashes.
Remove the parentheses and everything will be fine. That will look like