1

I have a String object:

NSString* name = @"John Smith";

and another String object:

NSString* intro =@"Hello this is ";

I want to be able to change the name from the UI make it within the introduction, so I tried:

_introduction = (@"Hello this is, %@", _name);

However, only the name is getting printed when I do:

NSlog(@"%@",_introduction);

I want both sentences to be printed by printing the intro object.

2
  • It's not the same question. I tried the answer included in the other question. However, the answer I was looking for is the one below. Commented Mar 26, 2019 at 21:12
  • The answer? There are many. Look at the second answer, it covers your question. It's exactly the same question Commented Mar 26, 2019 at 21:19

1 Answer 1

1

I'm not sure what (@"Hello this is, %@", _name); does or if that's even correct syntax, but typically to do what you're trying, you'd do something like this:

introduction = [NSString stringWithFormat:@"%@ %@", intro, name];
Sign up to request clarification or add additional context in comments.

2 Comments

I thought this is how enter an object within a String. Thank you for helping.
It is in correct syntax. The komma operator , evaluates both operands (@"Hello This is, %@" and _name), throws away the result of the first operand and returns the result of the second operand (_name). The parenthesis do simply nothing. Since the first operand is side-effect free, it is simply equivalent to introduction = _name.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.