Why print() is printing my String as an optional?

后端 未结 4 1919
醉酒成梦
醉酒成梦 2021-01-23 02:41

I have a dictionary and I want to use some of its values as a key for another dictionary:

let key: String = String(dictionary[\"anotherKey\"])

4条回答
  •  甜味超标
    2021-01-23 03:34

    You are misunderstanding the result. The String initializer does not return an optional. It returns the string representation of an optional. It is an non-optional String with value "Optional(42)".

提交回复
热议问题