开发者

Why my message become some monster char?

    NSString *msg = [[NSString alloc]initWithFormat:@"Hello %s, What do you do", (self.isUser ? @"User" : @"Guest")];
    NSLog(msg);

Whe开发者_C百科n I print the msg, it show that this is "†¶·»,", instead of user/guest, what's happen?


You need to use "%@" instead of "%s" on your format string if you are using NSString instances. Like this:

NSString *msg = 
   [[NSString alloc]initWithFormat:@"Hello %@, What do you do", (self.isUser ? @"User" : @"Guest")];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜