Search code examples
stringswift

Does Swift support string block?


Languages such as Ruby and Python both support string block. Such as:

a = '''
  Hello
  World
'''

Does Swift support string block?


Solution

  • No. As outlined in the Lexical Structure of the Swift programming language introduction, string literals are enclosed within one single pair of quotes and must not contain newlines.

    The grammar specifies that:

    string-literal → " quoted-text "
    quoted-text → quoted-text-item quoted-text opt
    quoted-text-item → escaped-character
    quoted-text-item → ( expression )
    quoted-text-item → Any Unicode extended grapheme cluster except " , \ , U+000A, or U+000D
    [...]

    Where U+000A and U+000D are newline and carriage return characters, respectively.

    At the moment, there is no other kind of string-literal.