<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On May 18, 2016, at 09:38, Ray Fix via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><br class=""><blockquote type="cite" class="">On May 18, 2016, at 3:56 AM, Artyom Goncharov via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:<br class=""><br class="">var noOptDict = ["one": 1, "two": 2, "three": 3 ]<br class="">noOptDict["one"] = nil<br class=""></blockquote><br class="">Wow, interesting. &nbsp;To me this was surprising behavior too.<br class=""><br class="">The comment for Dictionary subscript &nbsp;says:<br class=""><br class=""> &nbsp;&nbsp;&nbsp;/// Access the value associated with the given key.<br class=""> &nbsp;&nbsp;&nbsp;///<br class=""> &nbsp;&nbsp;&nbsp;/// Reading a key that is not present in `self` yields `nil`.<br class=""> &nbsp;&nbsp;&nbsp;/// Writing `nil` as the value for a given key erases that key from<br class=""> &nbsp;&nbsp;&nbsp;/// `self`.<br class=""><br class="">Which is exactly what it is doing. &nbsp;As the Zhaoxin said, you can use updateValue (and removeValueForKey) to get better results when dealing with optional dictionary values.</div></div></blockquote><br class=""></div><div>There’s a bit more discussion of this on the Apple Swift blog:&nbsp;<a href="https://developer.apple.com/swift/blog/?id=12" class="">https://developer.apple.com/swift/blog/?id=12</a></div><div><br class=""></div><div>Jordan</div><br class=""></body></html>