Plist won't copy to documents directory

Posted by John on Stack Overflow See other posts from Stack Overflow or by John
Published on 2010-03-22T02:09:53Z Indexed on 2010/03/22 2:11 UTC
Read the original article Hit count: 312

Filed under:
|

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 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

© Stack Overflow or respective owner

Related posts about iphone-sdk

Related posts about nsfilemanager