Articles, podcasts and news about Swift development, by John Sundell.

Multiline string literals don’t require quotes to be escaped

Published on 27 Aug 2018
Basics article available: Strings

One 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>&lt;<span class="type">String</span>&gt;
""")