I’m getting garbage values when manipulating some of my NSString objects. I think the problem stems from my misunderstanding of how NSString works at a basic level. Below, I have a object which has a string pointer as a synthesized property. When I try to log it out directly, the compiler gives me a warning, but it does log out the value I expect. On the very next line, I try to log that string out the proper way but I end up getting garbage.
Code snippet
MyObject *object = [self.objects objectAtIndex:indexPath.row];
NSString *myString = object.myString;
NSLog(myString); // format not a string literal and no formal arguments
NSLog(@"formatted = %s", myString);
Output
2011-05-16 13:06:51.137 MyProgram[917:207] thisValueIsGood
2011-05-16 13:06:51.138 MyProgram[917:207] formatted = `å
This problem has snowballed onto other functions which use this final string. When I concatenate that string with other strings, I get even more garbage.
NSString is an object, instead of
%s, use%@.