无法使用NSKeyedArchiver归档NSDictionary - 方法不会被调用

时间:2015-06-18 19:19:47

标签: ios objective-c cocoa-touch nskeyedarchiver archiving

我最近遇到了一个问题,由于某些原因我无法让Xcode调用archiveRootObject:toFile:方法。我认为它与NSMutableDictionary包含的内容有关,因为我已经能够用一个保存得很好的超级简单字典替换我想说的NSMutableDictionary,如下所示: / p>

NSDictionary *dict = @{
                       @"lea": @"marolt",
                      };

我要做的是归档三件事:

  • NSMutableArray * events
  • NSMutableArray * allDates
  • NSDictionary * eventsDictionary

以下是要归档的代码:

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"];

我还要提一下,在归档之前,我尝试归档的所有对象都不为空。他们应该是他们应有的一切。如果它有帮助,这里是对象在归档之前包含的内容(为方便起见,我目前只尝试使用1个对象)。

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年6月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} “       );

我有一个Cache课程,我已经实现了这些方法:

- (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;
}

所以,我现在不知所措。请帮帮忙?

0 个答案:

没有答案