0

我想比较两个字典及其键和值。我的以下代码返回错误。

NSLog(@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"doc_GETNEWS"]);
NSLog(@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"doc_GETNEWS_next"]);

    if([[NSUserDefaults standardUserDefaults] objectForKey:@"doc_GETNEWS_next"]!=nil)
    {

        NSDictionary *firstCache=[[NSUserDefaults standardUserDefaults] objectForKey:@"doc_GETNEWS"];
        NSDictionary *secondCache=[[NSUserDefaults standardUserDefaults] objectForKey:@"doc_GETNEWS_next"];

        NSLog(@"%@",firstCache);
        NSLog(@"%@",secondCache);
        //not equal then store it to main cache
        if(![firstCache isEqualToDictionary:secondCache])
        {
            [[NSUserDefaults standardUserDefaults] setObject:secondCache forKey:@"doc_GETNEWS"];
            [[NSUserDefaults standardUserDefaults] synchronize];
        }
    }

我收到错误

if(![firstCache isEqualToDictionary:secondCache]) 

在这个声明中。like

[__NSCFArray isEqualToDictionary:]: unrecognized selector sent to instance 0x85247a0

Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: '-[__NSCFArray isEqualToDictionary:]: unrecognized selector 
sent to instance 0x85247a0'

不是这样:我在两个 NSLOG 中都成功获取了数据。

4

1 回答 1

4

该错误意味着您的firstCache对象实际上不是一个NSDictionary但实际上是一个NSArray.

于 2012-05-19T05:22:22.053 回答