Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Objective-C Basics (Retired) Foundation Framework NSString

Paul Lacey
Paul Lacey
4,899 Points

Hey isn't this a correct answer?

NSString *color = @"Purple";
NSString *preference = @"My favorite color is ";
NSString *favorite = [color stringByAppendingString:preference];

Why won't it go through?

Update: Really just a question for the course makers. I think the test conditions are a bit off...

EDIT:I put objective-c so it highlights in the right way. Check out how i did it by looking at edit and see what i did. -Aurelian

2 Answers

Milo Winningham
seal-mask
.a{fill-rule:evenodd;}techdegree
Milo Winningham
Web Development Techdegree Student 3,317 Points

I think you've got the strings reversed. Appending preference to color would result in the string "PurpleMy favorite color is ".

Patrick Cooney
Patrick Cooney
12,216 Points

I believe this would give you "Purple My favorite color is ". Perfectly acceptable if you're Yoda. :-P if it helps, think of stringByAppendingString as a very long form of a + sign like you'd use in javascript or Java.