This article has been archived, as it was published several years ago, so some of its information might now be outdated. For more recent articles, please visit the main article feed.
Multiline string literals don’t require quotes to be escaped
Basics article available: StringsOne really nice benefit of Swift’s multiline string literals - even for single lines of text - is that they don’t require quotes to be escaped. Perfect when working with things like HTML, or when creating a custom description for an object.
let html = highlighter.highlight("Array<String>")
XCTAssertEqual(html, """
<span class="type">Array</span><<span class="type">String</span>>
""")

Swift by Sundell is brought to you by the Genius Scan SDK — Add a powerful document scanner to any mobile app, and turn scans into high-quality PDFs with one line of code. Try it today.