比较NSDictionary [英] Comparing NSDictionary

查看:78
本文介绍了比较NSDictionary的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to compare two dictionaries along with its key and value. My following code returns an error.

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]) 

在此声明中。似乎

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

NOT that: I got data successfully in Both NSLOG.

推荐答案

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

That error means your firstCache object isn't actually an NSDictionary but is actually an NSArray.

这篇关于比较NSDictionary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆