Search code examples
swiftescapingnewline

escape characters in Swift


I specifically am wondering how you could escape a newline in Swift, but generic escape characters would be great too.

In Python you can do this:

print("Dear grandma, \nHow are you?")

How can you do this in Swift?


Solution

  • Newlines as \n work in Swift string literals too.

    Check out the docs: Special Unicode Characters in String Literals