println dictionary has “Optional”

Swift dictionaries are returning optionals for safety. If you try to access a key which does not exists that would give you nil.

You can also use subscript syntax to retrieve a value from the dictionary for a particular key. Because it is possible to request a key for which no value exists, a dictionary’s subscript returns an optional value of the dictionary’s value type. If the dictionary contains a value for the requested key, the subscript returns an optional value containing the existing value for that key. Otherwise, the subscript returns nil

From The Swift Programming Language

and

Use subscripting to access the individual elements in any dictionary.
The value returned from a dictionary’s subscript is of type ValueType? — an optional with an underlying type of the dictionary’s ValueType

From the Swift Standard Library Reference

Leave a Comment