DEV Community

Arpan Patel
Arpan Patel

Posted on

Swift Multiline Magic: Say Goodbye to Annoying Line Breaks!"

If you are new to Swift and find yourself encountering those annoying \n characters after each statement in multiline code, fret not. While they indicate a new line, there's a simple trick to remove them and still maintain clean code formatting.
By adding a backslash () at the end of each line, you can effectively break multiline statements without the unwanted line breaks:

let greeting = "Hello, " +
"world!"

However, keep in mind that Swift doesn't allow a backslash at the end of the last line in a multiline statement. So, remember to avoid that to prevent any errors.
That's it for this quick tip! Stay tuned for more exciting Swift insights in our next blog.
Peace out! ✌️

Top comments (0)