上QQ阅读APP看书,第一时间看更新
Accessing an item in a dictionary
When trying to access an item inside a dictionary, you will always receive an optional value. The reason for this is that you could potentially receive nil if the value does not exist. So, you should always use an if...let statement to safeguard your code:
if let numChickenPrice = dictPizzas["chicken"] { print(numChickenPrice) }
Your code should now look like this: