The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

331319 (3) [Avatar] Offline
#1
I have attached the example to show what I mean. \n appears at the end of anything I write in the text bracket.
Tanmay Bakshi (1) [Avatar] Offline
#2
Hi - it's because the playground does not support multi-line text in the output pane. Since it cannot display another line, it displays "\n" in the output pane, which you are viewing. However, if you were to run this on a real iOS/macOS app, it will not show the "\n".

Also, if you go to the menu: "View -> Debug Area -> Show Debug Area (Command-Shift-Y)", it will toggle the "Debug Area" of the playground, as a horizontal pane on the bottom of your screen.

You can see the result of your "print" statements there, with multi-line support. In this area, you will see that the "\n" gets translated into a new line, since "\n" actually means "New Line".

I'll give you an example. If you enter the following command:
print("Hello, One\nTwo\nThree!")


Then, in the output pane, you see:
"Hello, One\nTwo\nThree!\n"
But in the Debug Area (again, at the bottom of the screen), you should see:
Hello, One
Two
Three!

Also, all
print()
statements in Swift (2 and later), have a new line at the end, which shows up in the Playground's output pane.

I hope this answers your question. If not, feel free to write back on the forum, and if you have any more questions, please create another thread.

- Tanmay Bakshi
P.S. Sorry for the late reply!
331319 (3) [Avatar] Offline
#3
Thanks for the detailed reply, makes a lot more sense now!