[英]Why am I getting “[__NSArrayI allKeys]: unrecognized selector sent to instance” / why is NSDictionary transforming?
查看此[__NSArrayI allKeys]: unrecognized selector sent to instance
错误,似乎是在向NSArray发送用于NSDictionary
的allKeys
消息时发生的,但在这种情况下,我非常清楚地将其发送到NSDictionary。
这是与Pocket API接口时使用的代码:
NSDictionary *articles = [response objectForKey:@"list"];
// Create an array we can use to sort the keys (and thus the articles) in order of when they were added
NSMutableArray *allKeys = [[articles allKeys] mutableCopy];
那里的最后一行导致错误。 但是articles
非常明确地声明为NSDictionary吗? 为什么不喜欢它?
奇怪的是,如果我在运行时检查它,则说它是一个NSArray! 为什么会改变?
(lldb) po articles
$5 = 0x082103e0 <__NSArrayI 0x82103e0>(
)
(lldb) po [articles class]
$6 = 0x01b83b8c __NSArrayI
(lldb)
它可以在您的代码中声明为字典,但这并不能使其成为字典。 它确实是一个数组,这就是为什么您会得到异常。 检查您的response
以便您知道应该做什么。
您的代码可以编译,因为编译器不知道它将是一个数组,并且相信您它将是一个字典。 这样做是因为objectForKey:
返回id
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.