I am experiencing strange behaviour with NSUserDefaults
. I am initially storing an array to the user defaults in my AppDelegate.m:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSArray *weekdayIDs = [defaults objectForKey:@"weekdayIDs"];
if (weekdayIDs == nil) {
weekdayIDs = [NSArray arrayWithObjects:@"su", @"mo", @"tu", @"we", @"th", @"fr", @"sa", nil];
[defaults setObject:weekdayIDs forKey:@"weekdayIDs"];
}
[defaults synchronize];
Now in a different view controller ContentViewController.m, I want to retrieve the array:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSArray *weekdayIDs = [defaults objectForKey:@"weekdayIDs"];
But I just get an array without objects, although its count == 7
. I also used arrayForKey:
but with the same result. I added a screenshot from my breakpoint.
I am regularly using NSUserDefaults
, but currently I am bit stuck on this. It's probably a stupid mistake, anyone care to help?
Thank you so much!
-- Update:
I also figured it might be a problem with the init of the NSArray in the first place, but even replacing its objects with manually created NSString *dwid_su = [NSString stringWithString:@"su"];
didn't work.