Good morning, I made an IBAction method which saves some objects to an array:
-(IBAction)saveToFav:(id)sender
{
NSUserDefaults *newDefaults = [NSUserDefaults standardUserDefaults];
favorites = [[NSMutableArray alloc]initWithArray:[newDefaults mutableArrayValueForKey:@"favorites"] copyItems:YES];
// check if array already contains an object
if (![favorites containsObject:self.title])
{
[favorites addObject:self.title];
}
[newDefaults setObject:favorites forKey:@"favorites"];
}
However, when I call this method app crashes with error:
[NSKeyValueSlowMutableArray getObjects:range:]: value for key
favorites of object 0x8939030 is nil’
Why this happens ?
Thanks!
Max
It seems like your data (favorites) has not been written to your defaults.You can forcesave your defaults by running this: