Skip to content

Need to add database first #11

@paresh-navadiya

Description

@paresh-navadiya

Thanks for library. But need to add database

pragma mark -

pragma mark - Copy DataBase Method

-(void)copyDatabaseToDocumentDirectoryWithName:(NSString *)name
{
NSString *path = [[NSBundle mainBundle]pathForResource:[[name lastPathComponent]stringByDeletingPathExtension] ofType:[name pathExtension]];

if ([[NSFileManager defaultManager] fileExistsAtPath:path])
{
    NSArray *pathArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
    NSString *documentsDirectory = [pathArray objectAtIndex:0];
    NSString *strFileDBPath = [documentsDirectory stringByAppendingPathComponent:name];

    if ([[NSFileManager defaultManager] fileExistsAtPath:strFileDBPath])//File exists in document directory
    {
        NSLog(@"Database exists");
    }
    else //File doesnot exists in document directory
    {
        //Need to copy file in document directory
        NSError *error = nil;
        if ([[NSFileManager defaultManager] copyItemAtPath:path toPath:strFileDBPath error:&error])
        { //copied successfully
            NSLog(@"Database copied");
        }
        else
        { //not copied
            NSLog(@"Database not copied");
        }
    }
}
else
{
    NSLog(@"Database file does not exists");
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions