Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3405826
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:33:11+00:00 2026-05-18T05:33:11+00:00

My application uses a database and at the beginning I want to check if

  • 0

My application uses a database and at the beginning I want to check if the database is already copied to the documents directory. If it isn’t it is supposed to be copied there.

What might be wrong with the code below? It worked fine for me until this morning… For some reason the database that is created in the documentsDirectory of the iPhone is completely empty.

- (void)viewDidLoad {
    [super viewDidLoad];
    self.databaseName = @"iWorkoutDatabase";
    NSArray *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDir = [documentsPath objectAtIndex:0];
    self.databasePath = [[documentsDir stringByAppendingPathComponent:databaseName] retain];
}

- (void)checkAndCreateDatabase{
    BOOL databaseIsSaved;

    NSFileManager *fileManager = [NSFileManager defaultManager];
    databaseIsSaved = [fileManager fileExistsAtPath:databasePath];
    if (databaseIsSaved == YES) {
        return;
    }
    else {

        NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName];
        [fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil];
    }
    [fileManager release];
}

I’m going crazy trying to figure this out so it would be great if someone could help me…
EDIT: I added the relevant code from the viewDidLoad method and I looked at the documents path from the iPhone simulator and a file was actually created there but it was an empty one.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T05:33:12+00:00Added an answer on May 18, 2026 at 5:33 am

    The code should work, I think. However, there are a few things left to improve that might also solve your problems:

    • do not release a shared instance — in your case don’t release the fileManager
    • Use pathForResource:ofType: to get the full path of your file directly, instead of creating the path on your own

    • Where is databasePath coming from? Is is set correctly?

    • Did you check the database file included with your app, maybe it’s broken?
    • Did you try to do a clean build?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that uses a database on SQL Server and I want
Is there any good/simple asp.net MVC application that uses NoSQL database(cassandra). Any suggestion.
I have this Java application which uses a MySql Database which I want to
My Java application uses a .mdb database and i want to run this application
My application uses MS access database to save some sensitive information. Though that information
I have an Android application that uses the Android database to create tables and
My WPF application uses Entity Framework 4.0 with a SQL Server CE database. And
I have an older web application that uses a MySQL Database (MYISAM). I noticed
We have a sharepoint based application that uses a custom database for storing metadata/files
I have a desktop .NET WPF application witch uses an embedded database (SQLite). Where

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.