Reputation: 21
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.
Upvotes: 2
Views: 151
Reputation: 2941
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];
Upvotes: 1
Reputation: 4040
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];
Upvotes: 3