开发者

Plist won't copy to documents directory

开发者 https://www.devze.com 2022-12-23 22:07 出处:网络
I have a plist file in my resources group in xcode. I am trying to copy this into my documents directory on app launch. I am using the following code (taken from a sqlite tutorial):

I have a plist file in my resources group in xcode. I am trying to copy this into my documents directory on app launch. I am using the following code (taken from a sqlite tutorial):

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开发者_如何学Python 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.

Any idea what is wrong?

Thanks


You're missing a file separator:

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

or, better, use:

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

精彩评论

暂无评论...
验证码 换一张
取 消