[swift-dev] about NSDictionary question

David Smith david_smith at apple.com
Wed Feb 24 03:58:20 CST 2016


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/50ddb38b/attachment.html>


More information about the swift-dev mailing list