SR-3286 Dictionary element not removed in case of the value nil assignment
According to Documentation:
If you assign nil as the value for the given key, the dictionary removes that key and its associated value.
In the following example, the key-value pair for the key "Aquamarine" is removed from the dictionary by assigning nil to the key-based subscript.
This works pretty well as long as I follow the example by using a nil literal to remove key-values, or by using a non-Optional Dictionary. If I have an Optional-valued Dictionary and use any other forms of nil, the removal is not guaranteed. It is confusing even, especially the short-hand case (.none) and fully-qualified case (X?.none) produce different results.
See the attached image for code sample.
P.S.: Also it may be debatable whether the nil-removal syntax should apply to Optional-valued Dictionaries at all. Because the point of using a Optional-valued Dictionary is to store Optionals. And an empty collection (no keys) vs. a collection of nils (keys present) are not the same thing.
The text was updated successfully, but these errors were encountered: