escape dictionary key double quotes when doing println dictionary item in Swift

Xcode 7.1+

Since Xcode 7.1 beta 2, we can now use quotations within string literals. From the release notes:

Expressions interpolated in strings may now contain string literals. For example, “My name is (attributes[“name”]!)” is now a valid expression. (14050788)

Xcode <7.1

I don’t think you can do it that way.

From the docs

The expressions you write inside parentheses within an interpolated string cannot contain an unescaped double quote (“) or backslash (\), and cannot contain a carriage return or line feed.

You’d have to use

let someVar = dict["key"]
println("Some words \(someVar)")

Leave a Comment