<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="">Hi,<div class=""><br class=""></div><div class="">Try using setObject(forKey:) rather than setValue(forUndefinedKey:).</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>David</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Feb 24, 2016, at 1:12 AM, 张辉 via swift-dev &lt;<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="line-height: 1.7; font-size: 14px; font-family: Arial;" class=""><div class=""><span style="font-size: 18px;" class="">HI everybody:</span></div><div class=""><br class=""></div><div class=""><span style="font-size: 18px;" class="">I have a question about NSDictionary.</span></div><div class=""><span style="font-size: 18px;" class="">I defined a instance of NSDictionary, when I set value to this instance , it throw a exception.</span></div><div class=""><br class=""></div><div class=""><span style="font-size: 18px;" class="">code:</span></div><div class=""><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">let</span> userDict = <span style="font-variant-ligatures: no-common-ligatures; color: #6122ae" class="">NSDictionary</span>()</div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class="">userDict.<span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">setValue</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">self</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #539aa4" class="">userName</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">text</span>!, forUndefinedKey: <span style="font-variant-ligatures: no-common-ligatures; color: #c91b13" class="">"userName2"</span>)</div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class="">exception:</div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class=""><b class="">2016-02-24 00:50:26.931 TravelAssistant[1900:792534] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[&lt;__NSDictionary0 0x7fc430404810&gt; setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key&nbsp;</b><b class="">userName2</b><b class="">.'</b></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class=""><b class=""><br class=""></b></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class="">How to fix this bug?<br class=""></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class="">thx.</div></div></div>_______________________________________________<br class="">swift-dev mailing list<br class=""><a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-dev<br class=""></div></blockquote></div><br class=""></div></body></html>