More noob questions... been struggling with NSLog to print out some NSStrings
So I have a label and have been fine with setting the Label dynamically but I also wanted to mirror some NSLog output.
Code:
// This line works fine for setting the label
yearresultslabel1.text = [NSString stringWithFormat:@"%s", "-- Test Label Text"];
// Now I wanted to dump the label out to the log....
NSLog(@"My Label now = %s", yearresultslabel1.text);
// The log outputs "My Label now = !%!@%" <- basically some funny characters instead of the string I want. Even tried this with a straight NSString I thought was setup correctly.
So what do I need to do to convert the text into something printable?
More noob questions... been struggling with NSLog to print out some NSStrings
So I have a label and have been fine with setting the Label dynamically but I also wanted to mirror some NSLog output.
Code:
// This line works fine for setting the label
yearresultslabel1.text = [NSString stringWithFormat:@"%s", "-- Test Label Text"];
// Now I wanted to dump the label out to the log....
NSLog(@"My Label now = %s", yearresultslabel1.text);
// The log outputs "My Label now = !%!@%" <- basically some funny characters instead of the string I want. Even tried this with a straight NSString I thought was setup correctly.
So what do I need to do to convert the text into something printable?
TIA.
I'm surprised that works for setting the label. change %s to %@.
It works in the first case because "..." is a C string, so %s is correct. In the second case, it is now dealing with an NSString object, so it needs to be %@.
It works in the first case because "..." is a C string, so %s is correct. In the second case, it is now dealing with an NSString object, so it needs to be %@.