Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

logicstudiouser

macrumors 6502a
Original poster
Feb 4, 2010
534
1,071
Whenever I type anything within the print( ) in the xcode playground. The message displays with an \n at the end of my message. How do I fix this issue?
This may be a stupid question, but I am still pretty new to iOS development.
You can see what I am talking about in the attached image.
 

Attachments

  • Hello swift error.png
    Hello swift error.png
    24.4 KB · Views: 211
The \n is actually a special String in most coding languages. The \ is an escape character in strings, meaning that it tells the computer that the next character after the \ is not a literal character, but a special character signifying something else. In order to print an actual "\", you must do \\. But back to the \n. \n, when placed inside a string, represents a new line, or a return. When something is printed in swift, a return is added to the end of the string inside the print() function so that consecutive print statements remain separate. That \n is just Xcode letting you know that, were you to run that swift code in an actual project, the full string printed out by the print() function to the console would have a return character afterwards.
 
  • Like
Reactions: logicstudiouser
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.