我正在尝试从文件中读取 2 个 NSMutableArrays。我正在保存和加载:
节省:
NSMutableDictionary *saveDict = [NSMutableDictionary dictionary];
[saveDict setValue:name forKey:@"name"];
[saveDict setValue:last_episodue forKey:@"whereat"];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingString:@"/ShopFile.sav"];
[saveDict writeToFile:filePath atomically:YES];
加载:
name = [[NSMutableArray alloc]init];
last_episodue = [[NSMutableArray alloc]init];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingString:@"/ShopFile.sav"];
NSDictionary *loadDict = [NSDictionary dictionaryWithContentsOfFile:filePath];
name = [loadDict valueForKey:@"name"];
last_episodue= [loadDict valueForKey:@"whereat"];
变量 name 和 last_episodue 已在头文件中声明。
程序编译并运行,但是在运行时尝试加载文件时,代码的 LOAD 部分执行,当它完成时,程序停止工作。这是调试信息(第一部分):
2012-10-13 12:14:10.801 series[5223:303] -[NSISRestrictedToZeroMarkerVariable copyWithZone:]: unrecognized selector sent to instance 0x1001900c0
2012-10-13 12:14:10.803 series[5223:303] -[NSISRestrictedToZeroMarkerVariable copyWithZone:]: unrecognized selector sent to instance 0x1001900c0
2012-10-13 12:14:10.906 series[5223:303] (
知道问题可能是什么吗?谢谢!
编辑:这是进行保存的文件的内容:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<array>
<string>a</string>
</array>
<key>whereat</key>
<array>
<string>a</string>
</array>
</dict>
</plist>