<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 <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> 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 <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> 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. To me this was surprising behavior too.<br class=""><br class="">The comment for Dictionary subscript says:<br class=""><br class=""> /// Access the value associated with the given key.<br class=""> ///<br class=""> /// Reading a key that is not present in `self` yields `nil`.<br class=""> /// Writing `nil` as the value for a given key erases that key from<br class=""> /// `self`.<br class=""><br class="">Which is exactly what it is doing. 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: <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>