gpt4 book ai didi

objective-c - .plist 文件写入失败!这段代码有什么问题?

转载 作者:行者123 更新时间:2023-11-28 20:36:26 31 4
gpt4 key购买 nike

此代码后我的 plist 文件中没有任何内容。我的代码有什么问题?

NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"aFile.plist"];
NSMutableDictionary *reqData = [NSMutableDictionary dictionaryWithContentsOfFile:finalPath];
/*
some modifications to "reqData"
*/
[reqData writeToFile:finalPath atomically:YES];

文件中没有任何内容。可能是什么问题?

最佳答案

你最好写到Document文件夹:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask,
YES);
NSString *path = [paths objectAtIndex:0];

更新

根据 NSDictionary Class Reference :

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.

在你的整个字典中是否有任何类型不是这些有效类型的对象?

关于objective-c - .plist 文件写入失败!这段代码有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10347680/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com