views:

24

answers:

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

When I print the msg, it show that this is "†¶·»,", instead of user/guest, what's happen?

+3  A: 

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")];
Pablo Santa Cruz