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 Swift Basics (retired) Types Strings

James Gray
James Gray
8,568 Points

\n in Swift2,

\n no longer makes a new line in strings...is there a way around this?

I hope someone answers

James Gray
James Gray
8,568 Points

So what i'm gathering is that this is not longer an operation that can be carried out with the update to swift. Xcode is now running swift2 and that comes with several changes. not only is the \n in strings no longer being taken, println and print were merged into one more convenient statement of just print. I'm sure there are many more changes that we will run into seeing as how the language is still new.

Just carry on learning swift2 using the lessons they provide on Treehouse and when it comes to quizzes and whatnot on treehouse just make a mental note that the syntax they want you to carry out is what you saw in their video's even though it's slightly different when you're actually in Xcode.

4 Answers

James Gray
James Gray
8,568 Points

From what i've gathered in swift2.0 the normal print function adds in the \n character unless you add in terminator: "" after what you're printing such as print("Hello", terminator:"")

i'm not entirely sure though hopefully this helps some.

Richard McGrath
Richard McGrath
5,597 Points

\n works in Swift 2 you just need to format it like this: print("To build an iPhone app we need to learn Swift \n")

ok thanks

James Gray
James Gray
8,568 Points

wouldn't that be redundant as it would say that you have two \n's? on the debugger pain it's not going to show either, however in the bar on the right it will say \n\n

Richard McGrath
Richard McGrath
5,597 Points

Technically you can use \n still in strings. I would not say adding \n to strings is redundant. While the new print function does automatically add an \n there are times when someone will want a second blank line after using the print function. From the question above it seems like Faisal still wanted to add a \n to his string. Hopefully the confusion has been cleared up now. :-)

thanks alot. just one more question how do I add a line? cause \n doesn't work?

ok thanks