Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift three double quotes

I am new to Swift. The docuentation says: Use three double quotes (""") for strings that take up multiple lines. Indentation at the start of each quoted line is removed, as long as it matches the indentation of the closing quote. For example:

let quotation = """
Even though there's whitespace to the left,
the actual lines aren't indented.
Except for this line.
Double quotes (") can appear without being escaped.
I still have \(apples + oranges) pieces of fruit.
"""

However, I copied this example and pasted in my xcode playground and it shows an error:

Playground execution failed: error: SwiftBasics.playground:9:19: error: 
unterminated string literal
let quotation = """

What am I doing wrong ?

like image 950
jreft56 Avatar asked Jun 06 '17 18:06

jreft56


People also ask

How do you add double quotes in Swift?

To include quotes inside a string in Swift, escape the quote symbol with backslash character, i.e., place a backslash character before the double quote inside the string.

How do I remove double quotes from a string in swift 5?

To remove double quotes just from the beginning and end of the String, we can use a more specific regular expression: String result = input. replaceAll("^\"|\"$", ""); After executing this example, occurrences of double quotes at the beginning or at end of the String will be replaced by empty strings.

How do you pass a double quote in a string?

Double Quotes inside verbatim strings can be escaped by using 2 sequential double quotes "" to represent one double quote " in the resulting string. var str = @"""I don't think so,"" he said. "; Console. WriteLine(str);

How do you display a double quote inside a string that begins and ends with double quotes?

If you need to use the double quote inside the string, you can use the backslash character. Notice how the backslash in the second line is used to escape the double quote characters. And the single quote can be used without a backslash.


1 Answers

I assume you are using Xcode 8 or earlier. Multi line String Literals have been implemented in Swift 4. You can only use them with Xcode 9 Beta or by including the open source Swift 4 toolchain in your Xcode at the moment.

like image 144
Jens Meder Avatar answered Sep 19 '22 13:09

Jens Meder