Plist不会复制到文档目录

Joh*_*ohn 4 iphone nsfilemanager

我在xcode的资源组中有一个plist文件.我想在app启动时将其复制到我的文档目录中.我使用以下代码(取自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]);
}
Run Code Online (Sandbox Code Playgroud)

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

知道什么是错的吗?

谢谢

nic*_*bot 10

你错过了一个文件分隔符:

... stringByAppendingString:@"/ActiveFeedsPlist.plist"];
Run Code Online (Sandbox Code Playgroud)

或者,更好,使用:

... stringByAppendingPathComponent:@"ActiveFeedsPlist.plist"];
Run Code Online (Sandbox Code Playgroud)