Search code examples
iphoneiosnsstringnsdictionary

convert NSDictionary to NSString


I am trying to put the content of an NSDictionary into an NSString for testing, But have no idea how to achieve this. Is it possible? if so how would one do such a thing?

The reason I am doing this, Is I need to check the content of a NSDicitonary without the debugger running on my device. as I have to delete the running app from multitasking bar of the ios so I can see if the values I am saving into the dictionary are still available afterwards.


Solution

  • You can call [aDictionary description], or anywhere you would need a format string, just use %@ to stand in for the dictionary:

    [NSString stringWithFormat:@"my dictionary is %@", aDictionary];
    

    or

    NSLog(@"My dictionary is %@", aDictionary);