0

我正在尝试从文件中读取 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>
4

1 回答 1

4

This is kind of a shot in the dark, since I can't tell without more context what your memory management looks like, but I just had this issue stemming from a variable whose value was not retained properly (we were assigning it using objc_setAssociatedObject but passing OBJC_ASSOCIATION_ASSIGN as the objc_AssociationPolicy). The pointer I held consistently ended up pointing over to an instance of NSISRestrictedToZeroMarkerVariable.

Since NSISRestrictedToZeroMarkerVariable is not a publicly-exposed class, what you're seeing is most likely the result of a memory overwrite. Set an exception breakpoint in Xcode and check out which line is throwing this error, and then track your memory management for that variable.

于 2013-11-21T23:26:59.047 回答