简体   繁体   English

Plist不会复制到文档目录

[英]Plist won't copy to documents directory

I have a plist file in my resources group in xcode. 我在xcode的资源组中有一个plist文件。 I am trying to copy this into my documents directory on app launch. 我想在app启动时将其复制到我的文档目录中。 I am using the following code (taken from a sqlite tutorial): 我使用以下代码(取自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]);
}

I am given the error " *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Failed to copy Plist. Error Operation could not be completed. No such file or directory'" in the console however. 我收到错误“***终止应用程序由于未捕获的异常'NSInternalInconsistencyException',原因:'无法复制Plist。错误操作无法完成。但是在控制台中没有这样的文件或目录'”。

Any idea what is wrong? 知道什么是错的吗?

Thanks 谢谢

You're missing a file separator: 你错过了一个文件分隔符:

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

or, better, use: 或者,更好,使用:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM