2012-05-19 68 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