Swift: How to print the meaning of a dictionary word inside a string expression?

For some reason, I just can't get this expression to work:

let expandedBio: Dictionary<String,AnyObject> = ["name":"Saurabh", "profession":"developer", "language":"java", "employed": true]

if let employed : AnyObject = expandedBio["employed"] {
    println("\(expandedBio[\"name\"]) is not available")
}

How to display the operator println? I get an error

Unexpected "" character  error in string interpolation

How to do it right?

+4
source share
1 answer

In the current version of Swift, you need to first put the value in your own constant / variable, and then use this.

if let employed : AnyObject = expandedBio["employed"] {
    let t = expandedBio["name"]
    println("\(t) is not available")
}
+5
source

Source: https://habr.com/ru/post/1544916/


All Articles