Here is a code snippet that I attempted to use to store and retrieve a mutable dictionary in NSUserDefaults. As my values in the dictionary are custom objects, I am using the NSKeyedArchiver. When I attempt to archive or unarchive, a NSInvalidArgumentException
is thrown.
// Save NSMutableDictionary to NSUserDefaults
NSData *data = [NSKeyedArchiver archivedDataWithRootObject: dataDictionary];
[[NSUserDefaults standardUserDefaults] setObject: data forKey: key];
[[NSUserDefaults standardUserDefaults] synchronize];
// Retrieve dictionary from NSUserDefaults
NSData* data = [[NSUserDefaults standardUserDefaults] objectForKey: key];
NSMutableDictionary* dataDictionary = [[NSKeyedUnarchiver unarchiveObjectWithData: data] mutableCopy];
Any help would be greatly appreciated!