I've recently gotten into a problem where for some reason I simply can not get Xcode to call the archiveRootObject:toFile:
method. I think it has something to do with what the NSMutableDictionary
contains, because I've been able to replace the NSMutableDictionary
I actually want to say with a super simple dictionary that saved just fine, like so:
NSDictionary *dict = @{
@"lea": @"marolt",
};
What I'm trying to do is archive three things:
- NSMutableArray *events
- NSMutableArray *allDates
- NSDictionary *eventsDictionary
Here's the code to archive:
self.eventsArray = [[NSMutableArray alloc] initWithArray:events];
self.eventsDictionary = eventsDictionary;
self.allDates = [[NSMutableArray alloc] initWithArray:allDates];
[self.eventTableView reloadData];
[tumblrHUD hide];
[[PECache sharedCacheModel] archiveObject:self.eventsArray toFileName:@"CachedEvents"];
[[PECache sharedCacheModel] archiveObject:self.allDates toFileName:@"CachedAllDates"];
[[PECache sharedCacheModel] archiveObject:self.eventsDictionary toFileName:@"CachedEventsDict"];
Let me also mention that before archiving, none of the objects I'm trying to archive is null. They're all as they should be. If it helps, here's what the objects contain before archiving (for convenience's sake, I'm currently trying with 1 object only).
events:
" {\n Candidate = \"Chris Christie\";\n City = Hampton;\n Date = \"2015-06-18\";\n Event = \"Town Hall Meeting\";\n EventType = 1;\n Price = 0;\n RSVP = 1;\n State = \"New Hampshire\";\n Time = \"05:00 PM\";\n Venue = \"Galley Hatch Restaurant\";\n Zone = ET;\n}"
allDates:
"2015-06-18"
eventsDictionary:
"2015-06-18" = ( " {\n RSVP = 1;\n candidate = \"\";\n candidateName = \"Chris Christie\";\n cityString = Hampton;\n costNum = 0;\n dateString = \"2015-06-18\";\n event = \"Town Hall Meeting\";\n eventType = 1;\n idNum = F5WUpDX5Ju;\n isGoing = 0;\n startDate = \"2015-06-18 21:00:00 +0000\";\n startTimeString = \"05:00 PM\";\n stateString = \"New Hampshire\";\n timeZone = ET;\n venue = \"Galley Hatch Restaurant\";\n}" );
I have a Cache
class where I've implemented these methods:
- (void) archiveObject:(id)object toFileName:(NSString *)fileName {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *cacheDirectory = paths[0];
NSString *filePath = [cacheDirectory stringByAppendingPathComponent:fileName];
[NSKeyedArchiver archiveRootObject:object toFile:filePath];
}
- (id) loadArchivedObjectWithFileName:(NSString *)fileName {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *cacheDirectory = paths[0];
NSString *filePath = [cacheDirectory stringByAppendingPathComponent:fileName];
id cachedObject = [NSKeyedUnarchiver unarchiveObjectWithFile:filePath];
return cachedObject;
}
So, I'm at a loss right now. Please help?