How do you compare 2 NSMutableArray ?
Different people might say this is a duplicate question, but i haven't found a solution to my problem after viewing most of the SO question.
There is a Person object, and it has the Fields Name, Age, Rank
I have a MutableArray which will save the data from NSUserDefaults. then it will see if the NSMutableArray is contains that particular object. if not it will add it to NSUserDefaults.
There is some problem when i am adding the person object to NSUserDefaults (I am adding the person object through an array, see code).
When i print [data count] it is always 0. So it might not be getting added to NSUserDefaults properly. Or i might be doing some mistake.
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
if (userDefaults ) {
NSArray *arr= [userDefaults objectForKey:@"person"];
data = [NSMutableArray arrayWithArray:arr];
NSLog (@"%i ", [data count]);
if (! [data containsObject:self.person] ) {
[data addObject:self.person];
NSArray *personarr= [NSArray arrayWithArray:data];
[userDefaults setObject:personarr forKey:@"person"];
[userDefaults synchronize];