Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSString returning jibberish

Totally lost with this one. Here's my code:

theColor = [NSString stringWithFormat:@"white"];
NSLog(@"%s", theColor);

Which is returing:

†t†å

I must be doing something stupid, but can not figure it out for the life of me.

like image 767
Ian McIntyre Silber Avatar asked Dec 16 '22 22:12

Ian McIntyre Silber


1 Answers

Change your print to:

NSLog(@"%@", theColor);

Hope it helps.

The thing is that %s expects a C-string (char array with a NULL terminator) and you are passing a NSString instance which is not the same as a C-string. The modifier you need in a format to print NSString content is %@.

like image 158
Pablo Santa Cruz Avatar answered Dec 28 '22 06:12

Pablo Santa Cruz