2

I am new to objective-C and I need help adding a variable to a string. in java, to add a variable to a string you have to do something like this:

 output = "Area: " + area + '\n' +"Circumference: " + circumference;

I can't figure out how to put that together to one string.

i have tried:

NSString *answer = [NSString stringWithFormat:@"Area : %.03f", area , "Circumference: %.03f", circumference];

and a couple other ways but it seems to not work.

1
  • What's type of area? Commented Nov 20, 2015 at 3:10

2 Answers 2

3

Objective-C requires you to define the format first and then pass the parameters.

Use this instead:

NSString *answer = [NSString stringWithFormat:@"Area : %.03f Circumference: %.03f", area, circumference];
Sign up to request clarification or add additional context in comments.

Comments

1

First I would say you need to learn more and see books and other references like.

here is how you will do in objective c

 NSString *answer = [NSString stringWithFormat:@"Area : %.03f Circumference: %.03f", area , circumference];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.