<div id="compose" contenteditable="true" aria-label="邮件正文" style="padding-left: 20px; padding-right: 20px; padding-bottom: 8px;"><div>I think you should use updateValue forKey method instead of subscript=value.</div><div><br></div><div>Subscript in Dictionary returns an Element?, you should not use it like a subscript in Array, which returns Element.</div><div><br></div><div>Zhaoxin<br><br><div class="acompli_signature">Get <a href="https://aka.ms/o0ukef">Outlook for iOS</a></div><br></div></div>
<div class="gmail_quote">_____________________________<br>From: Artyom Goncharov via swift-users <<a dir="ltr" href="mailto:swift-users@swift.org" x-apple-data-detectors="true" x-apple-data-detectors-type="link" x-apple-data-detectors-result="0">swift-users@swift.org</a>><br>Sent: 星期三, 五月 18, 2016 6:56 下午<br>Subject: [swift-users] Dictionary with optional values<br>To: <<a dir="ltr" href="mailto:swift-users@swift.org" x-apple-data-detectors="true" x-apple-data-detectors-type="link" x-apple-data-detectors-result="3">swift-users@swift.org</a>><br><br><br>Hi, here is the playground snippet:<br><br>var noOptDict = ["one": 1, "two": 2, "three": 3 ]<br>noOptDict["one"] = nil<br>noOptDict // “one” is gone<br><br>var optDict: [String: Int?] = ["one": 1, "two": 2, "three": nil]<br>optDict["one"] = nil<br>optDict // “one” is gone but “three” is still there<br><br>So the first dict instance works as it should, the second using opt values allows to store nil but deletes the key when you assign nil. Is it bug, feature, or both?<br><br>Best wishes,<br>Artyom<br>_______________________________________________<br>swift-users mailing list<br><a dir="ltr" href="mailto:swift-users@swift.org" x-apple-data-detectors="true" x-apple-data-detectors-type="link" x-apple-data-detectors-result="4">swift-users@swift.org</a><br><a dir="ltr" href="https://lists.swift.org/mailman/listinfo/swift-users" x-apple-data-detectors="true" x-apple-data-detectors-type="link" x-apple-data-detectors-result="5">https://lists.swift.org/mailman/listinfo/swift-users</a><br><br><br></div>