0

I create a dictionary, and I want to use println() to print dictionary content,

but it doesn't work, and I don't know how to solve it..

Please help... Thanks

var dictionary = ["name":"herny","age":20]
println("name = \(dictionary["name"])");   <--- this doesn't work, compile error because dictionary["name"] in \()
henry4343
  • 3,871
  • 5
  • 22
  • 30

1 Answers1

1

You can't put things with quotes in a \( ), you'll need to assign it to a variable:

var dictionary = ["name": "henry", "age": "20"];
let name = dictionary["name"];
println("name = \(name)");
Alex Gaynor
  • 14,353
  • 9
  • 63
  • 113