我想比较两个字典及其键和值。我的以下代码返回错误。
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 中都成功获取了数据。