- iOS 12 Programming for Beginners
- Craig Clayton
- 144字
- 2021-07-02 15:05:03
Removing items from a dictionary
Next, let's learn how to remove an item from a dictionary. When deleting items from a dictionary, we have two primary ways of doing this. The first uses removeValue(forKey:). Let's add this right above our if...else statement that checks whether the dictionary is empty:
dictPizzas.removeValue(forKey: "chicken")
Your code should now look like this:

Let's look at the second way of removing dictionary items, which is by using the shorthand syntax. Add the following to Playgrounds, following on from the removeValue(forKey:) variable:
dictPizzas["meat"] = nil
Your code should now look like this:

Notice that, just like with updateValue(_:forKey:), removeValue(forKey:) will return you the value before it is removed. If you do not need the value, the shorthand syntax is the preferred method.
So far, we have covered arrays and dictionaries, and now we will review one last collection: sets.
- RCNP實驗指南:構(gòu)建高級的路由互聯(lián)網(wǎng)絡(BARI)
- Cisco OSPF命令與配置手冊
- 面向物聯(lián)網(wǎng)的CC2530與傳感器應用開發(fā)
- 物聯(lián)網(wǎng)安全與深度學習技術(shù)
- Hands-On Chatbots and Conversational UI Development
- 物聯(lián)網(wǎng)+BIM:構(gòu)建數(shù)字孿生的未來
- 網(wǎng)絡互聯(lián)技術(shù)(實踐篇)
- SSL VPN : Understanding, evaluating and planning secure, web/based remote access
- 城域網(wǎng)與廣域網(wǎng)(第2版)
- Kong網(wǎng)關(guān):入門、實戰(zhàn)與進階
- 5G技術(shù)與標準
- 一本書讀懂物聯(lián)網(wǎng)
- INSTANT LinkedIn Customization How-to
- LwIP應用開發(fā)實戰(zhàn)指南:基于STM32
- 新媒體交互藝術(shù)