How to move a plist from the bundle to the documents folder on iOS

ios, ipad, iphone, objective-c

Solution

If your plist name is "friends"

just use below code ( it will find whether the file exists or not and copies)

NSFileManager *fileManger=[NSFileManager defaultManager];
NSError *error;
NSArray *pathsArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);

NSString *doumentDirectoryPath=[pathsArray objectAtIndex:0];

NSString *destinationPath= [doumentDirectoryPath stringByAppendingPathComponent:@"friends.plist"];

NSLog(@"plist path %@",destinationPath);    
if ([fileManger fileExistsAtPath:destinationPath]){
    //NSLog(@"database localtion %@",destinationPath);
    return;
}
NSString *sourcePath=[[[NSBundle mainBundle] resourcePath]stringByAppendingPathComponent:@"friends.plist:];

[fileManger copyItemAtPath:sourcePath toPath:destinationPath error:&error];

that will copy plist from resources to documents directory

Problem

So all I want to know is how to move a plist from the bundle to the documents folder the first time an application runs, because I need it. Please I can't find out how to do it, so help me.

Original source

Related problems