ios - [__NSDictionaryI setObject :forKey:]: unrecognized selector sent to instance

标签 ios nsdictionary nsmutabledictionary foundation

我正在尝试将“dateTime”添加到我的字典中,定义如下:

Symptom Ranking: {
    5111ef19253b4a9150000000 = 1;
    5111f029253b4add4e000000 = 1;
    5111f036253b4a123d000001 = 1;
    5111f045253b4a404f000000 = 1;
}

NSLog(@"date selected: %@", [[self.datePicker date] description])

[self.results setObject:[[self.datePicker date] description] forKey:@"dateTime"];

应用程序崩溃,我得到这个:

Symptom Tracker[43134:c07] -[__NSDictionaryI setObject:forKey:]: unrecognized selector sent to instance 0x7603990
2013-02-06 08:15:58.741 Symptom Tracker[43134:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryI setObject:forKey:]: unrecognized selector sent to instance 0x7603990'
*** First throw call stack:
(0x171b012 0x1428e7e 0x17a64bd 0x170abbc 0x170a94e 0x521e 0x143c705 0x373920 0x3738b8 0x434671 0x434bcf 0x433d38 0x3a333f 0x3a3552 0x3813aa 0x372cf8 0x2652df9 0x2652ad0 0x1690bf5 0x1690962 0x16c1bb6 0x16c0f44 0x16c0e1b 0x26517e3 0x2651668 0x37065c 0x25dd 0x2505)

最佳答案

您的字典是不可变的 - 它是 NSDictionary 而不是 NSMutableDictionary。解决这个问题,它就会正常工作。

关于ios - [__NSDictionaryI setObject :forKey:]: unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14731353/

相关文章:

objective-c - 可变集合有文字语法吗?

ios - 最大宽度文本 UILabel swift 2 上的断线

ios Titanium 模块安装 : No Titanium folder in Library/Application Support folder

ios - UITableViewCell 滚动检测

objective-c - 无法将 'class' 用作 NSDictionary 中的键

ios - 'NSInvalidArgumentException '-[NSTaggedPointerString count]: unrecognized selector sent to instance 0xa006162696a614e6'

ios - 如何快速将对象设置为 NSMutableDictionary 中的键

ios - 应用程序从委托(delegate) View Controller 开始

objective-c - NSDictionary 错误 - 'Count of objects differs from count of keys'

ios - 如何在 iOS 中解析复杂的 JSON 数据