官术网_书友最值得收藏!

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:

主站蜘蛛池模板: 阿勒泰市| 丹阳市| 洱源县| 武威市| 乐业县| 沭阳县| 台北县| 邻水| 北票市| 翼城县| 贵港市| 赣榆县| 马公市| 杭锦旗| 常山县| 彝良县| 明光市| 威信县| 焉耆| 新兴县| 景东| 湘潭市| 营山县| 凯里市| 阿瓦提县| 南京市| 宜良县| 兰溪市| 晋中市| 潢川县| 武胜县| 海南省| 枣阳市| 莱芜市| 远安县| 吉林省| 绩溪县| 西青区| 靖州| 罗甸县| 大田县|