I'm trying to store both an integer and NSArray with the NSUserDefaults, but I only can correctly retrieve the integer. When I try to recover the NSArray, it returns an empty array.
I start with a custom class XMLParser.m.
//XMLParser.m
//NSArray 'stored' correctly contains 10 data objects. 'stored' is an NSArray property of the XMLParser class
numberOfEvents = [stored count];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:stored forKey:@"eventsList"];
[defaults setInteger:numberOfEvents forKey:@"numberOfEvents"];
[defaults synchronize];
But when I try to access the data in another class, ie. my AppDelegate, I get an empty NSArray
//myApplicationAppDelegate.m
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
int value = [defaults integerForKey:@"numberOfEvents"]; //returns 10
parsedEventsList = [defaults arrayForKey:@"eventsList"]; //parsedEventsList is an NSArray property of myApplicationAppDelegate class
int value2 = [parsedEventsList count]; //***returns 0***
I've even tried using
[defaults objectForKey:@"eventsList"]
and it's still returning nothing.
Thoughts? Thanks!