[swift-dev] about NSDictionary question

张辉 tianya_z at 163.com
Wed Feb 24 04:55:12 CST 2016


I change NSDictionary to NSMutableDictionary


it's resolved


thank you






At 2016-02-24 18:06:56, "张辉" <tianya_z at 163.com> wrote:

No such method


I use swift2.1


At 2016-02-24 17:58:20, "David Smith" <david_smith at apple.com> wrote:
Hi,


Try using setObject(forKey:) rather than setValue(forUndefinedKey:).


David


On Feb 24, 2016, at 1:12 AM, 张辉 via swift-dev <swift-dev at swift.org> wrote:


HI everybody:


I have a question about NSDictionary.
I defined a instance of NSDictionary, when I set value to this instance , it throw a exception.


code:
let userDict = NSDictionary()
userDict.setValue(self.userName.text!, forUndefinedKey: "userName2")


exception:
2016-02-24 00:50:26.931 TravelAssistant[1900:792534] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSDictionary0 0x7fc430404810> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key userName2.'


How to fix this bug?



thx.
_______________________________________________
swift-dev mailing list
swift-dev at swift.org
https://lists.swift.org/mailman/listinfo/swift-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20160224/44037311/attachment.html>


More information about the swift-dev mailing list