我遇到了一个问题。每次我启动我的应用程序时,它都会崩溃。这是我的代码。调试器说:[list count]
应用程序崩溃。我不知道。NSLog(@"%@", self.list);
正如预期的那样给了我一件东西......
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
data = [[NSData alloc] initWithContentsOfFile:filePath];
unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
NSMutableArray *array = [unarchiver decodeObjectForKey:@"TOWN"];
[unarchiver finishDecoding];
[unarchiver release];
[data release];
}
self.list = array;
NSLog(@"%@", self.list);
NSLog(@"count %i", [list count]);
打开的存档是这样创建的:
Adding *adding = [[Adding alloc] init];
adding.nummer = 1;
adding.stadt = stadt.text;
NSMutableData *data = [[NSMutableData alloc] init];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc]
initForWritingWithMutableData:data];
[archiver encodeObject:adding forKey:@"TOWN"];
[archiver finishEncoding];
[data writeToFile:[self dataFilePath] atomically:YES];
如果您需要任何进一步的代码,请告诉我。我会非常感谢任何帮助:)