ios - 将 NSDictionary 写入 plist

标签 ios plist nsdictionary writetofile

嗨,我正在尝试将 NSDictionary 写入文档文件夹中的 plist,但无法写入,我正在使用 writeToFile:atomically: 方法,该方法返回 False。完整代码为

-(void)writeData:(NSDictionary *)dicResponseData
{
    // get paths from root directory

    NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
    // get documents path
    NSString *documentsPath = [paths objectAtIndex:0];
    // get the path to our Data/plist file
    NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"Contractors.plist"];   

    [dicResponseData writeToFile:plistPath atomically: TRUE];  
}

该词典包含 25 个子词典。

最佳答案

字典中的所有对象都必须是属性列表对象。

This method recursively validates that all the contained objects are property list objects (instances of NSData, NSDate, NSNumber, NSString, NSArray, or NSDictionary) before writing out the file, and returns NO if all the objects are not property list objects, since the resultant file would not be a valid property list.

关于ios - 将 NSDictionary 写入 plist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10835135/

相关文章:

android - 在高 DPI 平板电脑或计算机上查看网页时,是否需要更改字体堆栈?

ios - 如何在设置动态值后将数据保存到 ios 中的 plist 中?

ios - 使用 NSPredicate 过滤包含字典的数组

iphone - 如何对包含 NSDictionary 的 NSArray 进行排序?

c++ - 从 C++ 调用 Swift 函数

ios - 使用nspredicate来获取具有最大属性值以及与一种关系的实体

ios - 获取按各自值升序排序的 NSDictionary 键

ios - Plist 从 URL 到 NSMutableArray

java - 为什么 XPATH (Java 7) 选择太多节点?

objective-c - NSDictionary 中的键可以重复吗?