ardakaraca ardakaraca - 1 year ago 158
Swift Question

How to remove a key-value pair from swift dictionary?

I want to remove a key-value pair from a dictionary like in example if possible.

var dict: Dictionary<String,String> = [:]
var willRemoveKey = "SomeKey"
dict.removePair(willRemoveKey) //that's what I need

Answer Source

You can use this:

dict[willRemoveKey] = nil

or this:


The only difference is that the second one will return the removed value (or nil if it didn't exist)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download