【问题标题】:Comparing NSDictionary比较 NSDictionary
【发布时间】:2012-05-19 05:14:17
【问题描述】:

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

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 中都成功获取了数据。

【问题讨论】:

    标签: iphone ios5


    【解决方案1】:

    该错误意味着您的firstCache 对象实际上不是NSDictionary,而是实际上是NSArray

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多