Plist does not copy to document directory

I have a plist file in my resource group in xcode. I am trying to copy this to my document directory when the application starts. I use the following code (taken from 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 was given the error "*** The application terminated due to the unselected exception" NSInternalInconsistencyException ", reason:" Failed to copy Plist. The operation error could not be completed, but the console does not have such a file or directory. "

Any idea what is wrong?

thanks

+4
source share
1 answer

You are missing a file separator:

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

or, better, use:

 ... stringByAppendingPathComponent:@"ActiveFeedsPlist.plist"]; 
+10
source

Source: https://habr.com/ru/post/1304724/


All Articles