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

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:

主站蜘蛛池模板: 商水县| 阿尔山市| 枝江市| 济南市| 龙州县| 临清市| 昌乐县| 三明市| 互助| 咸丰县| 许昌市| 长丰县| 石家庄市| 英德市| 深州市| 文昌市| 同江市| 皋兰县| 南岸区| 图们市| 于田县| 龙泉市| 札达县| 兴化市| 当雄县| 桓台县| 竹溪县| 赣州市| 荆州市| 叙永县| 墨玉县| 屯门区| 阿尔山市| 安岳县| 抚松县| 政和县| 建宁县| 镇赉县| 唐山市| 中超| 临洮县|