gpt4 book ai didi

iphone - 检查plist是否存在,如果不存在从这里加载

转载 作者:行者123 更新时间:2023-12-03 21:10:24 25 4
gpt4 key购买 nike

我正在尝试检查我的文档文件夹中是否存在 plist:如果是,则加载它,如果不从资源文件夹加载。

 - (void)viewWillAppear:(BOOL)animated
{
//to load downloaded file
NSArray *docpaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [docpaths objectAtIndex:0];
NSString *docpath = [documentsDirectory stringByAppendingPathComponent:@"downloadedfile.plist"];

//if document folder got file
if(docpath != nil)
{
NSDictionary *dict = [[NSDictionary alloc]
initWithContentsOfFile:docpath];
self.allNames = dict;
[dict release];
}
//on error it will try to read from disk

else {
NSString *path = [[NSBundle mainBundle] pathForResource:@"resourcefile"
ofType:@"plist"];
NSDictionary *dict = [[NSDictionary alloc]
initWithContentsOfFile:path];
self.allNames = dict;
[dict release];

}
[table reloadData];

我哪里出错了? plist 未从资源文件夹加载。

最佳答案

我认为如果您创建 NSFileManager 的实例,则可以使用文件存在方法

BOOL exists;
NSFileManager *fileManager = [NSFileManager defaultManager];

exists = [fileManager fileExistsAtPath:docPath];

if(exists == NO)
{
// do your thing
}

关于iphone - 检查plist是否存在,如果不存在从这里加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3651311/

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