簡體   English   中英

為什么我會收到“ [__NSArrayI allKeys]:無法識別的選擇器發送到實例” /為什么要進行NSDictionary轉換?

[英]Why am I getting “[__NSArrayI allKeys]: unrecognized selector sent to instance” / why is NSDictionary transforming?

查看此[__NSArrayI allKeys]: unrecognized selector sent to instance錯誤,似乎是在向NSArray發送用於NSDictionaryallKeys消息時發生的,但在這種情況下,我非常清楚地將其發送到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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM