【问题标题】:Array of Arrays - writing to File problem数组数组 - 写入文件问题
【发布时间】:2010-05-20 04:53:55
【问题描述】:

我的数组数组...我尝试通过缓冲文件中的数组以供以后重用来提高我的应用程序性能。

我有一个 NSMutableArray,它包含大约 30 个带有 NSNumber、NSDate 和 NSString 对象的 NSMutableArray。

我尝试使用此调用写入文件:

bool result = [myArray writeToFile:[fileMethods 
                                    getFullPath:[NSString 
                                                 stringWithFormat:@"iEts%@.arr", 
                                                 [aDate shortDateString]]] 
                       atomically:NO];

=> 结果 = FALSE。

Path方法是:

+ (NSString *) getFullPath:(NSString *)forFileName {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    return [documentsDirectory stringByAppendingPathComponent:forFileName];
}

并且 aDate 调用返回一个带有 ddMMyy 的 shortDateString。

NSLog

NSLog(@"%@", [fileMethods getFullPath:[NSString stringWithFormat:@"iEts%@.arr", 
                                                [aDate shortDateString]]]);

关于路径生成返回:

/Users/me/Library/Application Support/iPhone Simulator/User/Applications/86729620-EC1D-4C10-A799-0C638BB27933/Documents/iEts010510.arr

进一步:

  • 它一定与 数组数组,因为我也写了 3 更简单的数组(包含 NSStrings) 都成功了。
  • 使用 addObject 方法生成数组数组

有什么可能导致问题的想法吗?

【问题讨论】:

    标签: iphone objective-c xcode


    【解决方案1】:

    AFAIK 写入文件使用对象存档,因此您的数组数组中的某些对象无法存档。

    【讨论】:

    • 属性列表,不是对象归档。不过,一般效果相同。
    • 嗯,我按照您的指示开始测试编写子数组。似乎那些具有空 NSStrings 的人无法写入。添加单个空格字符也无济于事......
    • 不明白。 NSNumber、NSDate 和 NSString 都没有被报告为麻烦制造者。用一些文本填充我的空字符串也不会改变任何东西......很奇怪。在我的子数组枚举中,它在附加 1 个对象时写入子数组,从第二个对象开始,它会失败 ...
    【解决方案2】:

    您的阵列中是否有任何 NSNull?我不认为它们算作 plist 对象,因此会导致写入失败。

    【讨论】:

    • 我在数组中有空字符串,但是当我测试填充它们时,数组存储仍然失败 - 情况没有改变
    猜你喜欢
    • 2021-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-19
    • 1970-01-01
    • 1970-01-01
    • 2021-06-04
    相关资源
    最近更新 更多