Rookie swift coding question. Why is Xcode printing '\n'?

Discussion in 'iOS Programming' started by logicstudiouser, Jun 12, 2016.

  1. logicstudiouser macrumors 6502


    Feb 4, 2010
    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.

    Attached Files:

  2. iphonedude2008 macrumors 65816


    Nov 7, 2009
    Irvine, CA
    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.
  3. logicstudiouser thread starter macrumors 6502


    Feb 4, 2010

Share This Page