objective c - Compare two plist files or two NSDictionary in iOS -


i have downloaded plist file server, contains key value pair. once app resumes/restarts again have download file , check if file has changed.

below code download... storing key values in nsdictionary.

 task1 = [session datataskwithurl:[nsurl urlwithstring:[s3_server_url stringbyappendingstring:propfile]] completionhandler:^(nsdata *data, nsurlresponse *response, nserror *error) {     propfilepath = [documentsdirectory stringbyappendingstring:propfile];     nslog(@"destpath : %@", propfilepath);     [receiveddata appenddata:data];     nslog(@"succeeded! received %lu bytes of data",(unsigned long)[data length]);     [uiapplication sharedapplication].networkactivityindicatorvisible = no;     [data writetofile:propfilepath atomically:yes];      if(error == nil){         plistdictionary = [[nsdictionary dictionarywithcontentsoffile:propfilepath] retain];         [task2 resume];     } else {      }  }]; 

how can compare contents of 2 plist files or ns dictionary? function best suited above have on app create/resume/restart? should compatible both ios7 , ios8 sdk.

if want changed key follow this:- return array of changed keys.

create category nsdictionary

nsdictionary+newdict.h

#import <foundation/foundation.h>  @interface nsdictionary (newdict) - (nsarray*)changedkeysin:(nsdictionary*)d; @end 

nsdictionary+newdict.m

#import "nsdictionary+newdict.h"  @implementation nsdictionary (newdict)  - (nsarray*)changedkeysin:(nsdictionary*)d {     nsmutablearray *changedks = [nsmutablearray array];     for(id k in self) {         if(![[self objectforkey:k] isequal:[d objectforkey:k]])             [changedks addobject:k];     }     return changedks; } @end 

calling:-

#import "nsdictionary+newdict.h" 

and:-

nsarray *keys = [dict1 changedkeysin:dict2]; nslog(@"%@", keys);    

Comments