gpt4 book ai didi

objective-c - 我已成功将我的 plist 保存到文档目录中!现在我无法加载它

转载 作者:行者123 更新时间:2023-12-03 17:32:44 25 4
gpt4 key购买 nike

这段代码可以完美地将我的 plist 保存到文档目录中。

- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.rightBarButtonItem = self.addButtonItem;
NSString *path = [[NSBundle mainBundle] pathForResource:@"TitleArray" ofType:@"plist"];
NSMutableArray *tmpArray = [[NSMutableArray alloc]initWithContentsOfFile:path];
self.titles = tmpArray;
[tmpArray release];

//TESTING NEW CODE FOR SAVING TO DOC DIR
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *docDirPath = [documentsDirectory stringByAppendingPathComponent:@"TitleArray.plist"];

NSFileManager *fileManager = [NSFileManager defaultManager];

if(![fileManager fileExistsAtPath: docDirPath])
{
NSString *bundle = [[NSBundle mainBundle] pathForResource:@"TitleArray" ofType:@"plist"];

[fileManager copyItemAtPath:bundle toPath:docDirPath error:&error];

NSLog(@"plist is copied to Directory");
}

我无法弄清楚如何将 plist 加载回应用程序!

有人可以帮忙吗?谢谢。

最佳答案

NSString *path = [documentsDirectory stringByAppendingPathComponent:@"TitleArray.plist"];
NSArray * myList = [NSArray arrayWithContentsOfFile:path];
NSMutableArray *tmpArray = [myList mutableCopy];
self.titles = tmpArray;
[tmpArray release];

没用?

关于objective-c - 我已成功将我的 plist 保存到文档目录中!现在我无法加载它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4290024/

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