gpt4 book ai didi

iphone - Plist不会复制到文档目录

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

我在 xcode 的资源组中有一个 plist 文件。我试图在应用程序启动时将其复制到我的文档目录中。我正在使用以下代码(取自 sqlite 教程):

BOOL success;
NSError *error;

NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingString:@"ActiveFeedsPlist.plist"];

success = [fileManager fileExistsAtPath:filePath];
if (success) return;

NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingFormat:@"ActiveFeedsPlist.plist"];
success = [fileManager copyItemAtPath:path toPath:filePath error:&error];

if (!success) {
NSAssert1(0, @"Failed to copy Plist. Error %@", [error localizedDescription]);
}

我在控制台中收到错误“*** 由于未捕获的异常‘NSInternalInconsistencyException’而终止应用程序,原因:‘无法复制 Plist。错误操作无法完成。没有这样的文件或目录’”。

知道出了什么问题吗?

谢谢

最佳答案

您缺少文件分隔符:

... stringByAppendingString:@"/ActiveFeedsPlist.plist"];

或者更好的是,使用:

... stringByAppendingPathComponent:@"ActiveFeedsPlist.plist"];

关于iphone - Plist不会复制到文档目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2489648/

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