2012-05-19 100 views
0

我想比较两个词典及其键和值。我的下面的代码返回一个错误。比较NSDictionary

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]; 
     } 
    } 

我在这个statement.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' 

不就是让错误

if(![firstCache isEqualToDictionary:secondCache]) 

:我在NSLog的都得到了数据成功。

回答

4

该错误表示您的firstCache对象实际上不是NSDictionary,而是实际上是NSArray

+0

噢谢谢@Dave Delong – iChirag