- iOS 12 Programming for Beginners
- Craig Clayton
- 122字
- 2021-07-02 15:05:03
Checking the number of items in a dictionary
In addition to keys and values, we have other useful properties. We can see the number of items in a dictionary using the count property. Let's try that by adding the following:
print("There are \(dictPizzas.count) total pizzas.")
Now, your code and output should look like this:

Along with a count, we can check whether a dictionary is empty. Let's use this in an if...else statement by adding the following:
if dictPizzas.isEmpty { print("there are no pizzas") } else { print("There are \(dictPizzas.count) total pizzas.") }
Now, your code and output should look like this:

This kind of logic is helpful when you want to display something back to the user or hide a UI.
推薦閱讀
- 網絡教育學習指導
- MERN Quick Start Guide
- NB-IoT物聯網技術解析與案例詳解
- 區塊鏈輕松上手:原理、源碼、搭建與應用
- Microsoft Dynamics CRM 2011 Applications(MB2-868) Certification Guide
- 6G新技術 新網絡 新通信
- 網管工具使用與技巧大全
- 從實踐中學習手機抓包與數據分析
- 網絡工程實施技術與方案大全
- Hands-On Bitcoin Programming with Python
- 信息技術安全評估準則:源流、方法與實踐
- 一本書讀懂移動物聯網
- CDN技術詳解
- Scala Programming Projects
- 網絡設備配置與調試項目實訓