Include a variable inside a NSString?

后端 未结 2 559
旧时难觅i
旧时难觅i 2021-01-05 16:22

This works fine, we all know that:

NSString *textoutput = @\"Hello\";
outLabel.text = textoutput;

However, what if you want to include a v

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-05 16:52

    I have The Cure you're looking for, Robert Smith:

    if your variable is an object, use this:
    NSString *textOutput = [NSString stringWithFormat:@"Hello %@", Variable];

    The '%@' will only work for objects. For integers, it's '%i'.

    For other types, or if you want more specificity over the string it produces, use this guide

提交回复
热议问题