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

  • Home
  • SEARCH
  • 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 358547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:18:35+00:00 2026-05-12T12:18:35+00:00

I’m trying to write two applications (iphone and desktop) to achieve what’s been described

  • 0

I’m trying to write two applications (iphone and desktop) to achieve what’s been described in the following link:

core-data-is-it-possible-to-build-a-desktop-app-to-create-the-data-model-for-an

Ok. So I’ve created a very simple desktop app the has a single entity named Client with a string attribute field called name. I’ve also generated the corresponding Model class.

I’ve run the app added a couple of client names to the list and saved the file (as Testing.sqlite).

Now in my equivalent iphone app I’m attempting to load the file. I’ve generated the app initially using one of the application templates and included Core Data. NB: I’ve mirrored the Client entity and generated the corresponding Model class.

I’ve gone into my “application delegate” class and amended the persistentStoreCoordinator method to reference my “Testing.sqlite” file i.e.

    NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"Testing.sqlite"]];

I’ve also copied the saved desktop app file into the expected location i.e.

~/Library/Application Support/IPhone Simulator/User/... etc.

So now in theory at least each of the two apps should be the same.

However when I’m attempting to load the data from the it always seems to be empty. My code looks a little like this:

    // fetch the delegate.
TestingAppDelegate *app = (TestingAppDelegate *)[[UIApplication sharedApplication] delegate];
NSManagedObjectContext *managedObjectContext = [app managedObjectContext];

// construct the request.
NSFetchRequest *request = [[NSFetchRequest alloc] init]; 
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Client" inManagedObjectContext:managedObjectContext]; 
[request setEntity:entity]; 

// execute the request.
NSError *error;
NSArray *results = [managedObjectContext executeFetchRequest:request error:&error];

if (results == nil) { 
    // Handle the error.        
    NSLog(@"No data loaded");
} 

NSLog(@"Returned: %@", results);    

// finally release  
[results release]; 
[request release]; 

I can’t seem to figure out what’s going wrong. Any tips or suggestions would be totally appreciated.

When I’ve looked at the instance of the persistanceStoreCoordinator, managedObjectContext, resulting array (NSArray) whilst debugging I can see that it seems to contain 0 records for all of these. So I’m confused.

NB: The Testing.sqlite file contains entries.

Thanks in advance,
Matt

  • 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-12T12:18:35+00:00Added an answer on May 12, 2026 at 12:18 pm

    Simply copying the sqlite database file will not work when using Core Data.
    You need to fully replicate the persistent store you created in your desktop application.

    However, this may be a problem related to the fact that Core Data is not seeing your database file even though you copied it. Try the following:

    1) add your database file to your project in the resources group
    2) use this method to actually copy your database file in place

    - (NSString *) initialize_db {
        NSString *DATABASE_RESOURCE_NAME = @"testing";
        NSString *DATABASE_RESOURCE_TYPE = @"sqlite";
        NSString *DATABASE_FILE_NAME = @"testing.sqlite";
    
        // copy the database from the bundle if necessary
        // look to see if DB is in known location (~/Documents/$DATABASE_FILE_NAME)
    
    
        NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString *documentFolderPath = [searchPaths objectAtIndex: 0];
            NSString *dbFilePath = [documentFolderPath stringByAppendingPathComponent: DATABASE_FILE_NAME];
            [dbFilePath retain];
    
            if (! [[NSFileManager defaultManager] fileExistsAtPath: dbFilePath]) {
                // didn't find db, need to copy
                NSString *backupDbPath = [[NSBundle mainBundle]
                                          pathForResource:DATABASE_RESOURCE_NAME
                                          ofType:DATABASE_RESOURCE_TYPE];
                if (backupDbPath == nil) {
                    // couldn't find backup db to copy, bail
                    NSLog (@"couldn't init db");
                    return NULL;
                } else {
                    BOOL copiedBackupDb = [[NSFileManager defaultManager]
                                           copyItemAtPath:backupDbPath
                                           toPath:dbFilePath
                                           error:nil];
                    if (! copiedBackupDb) {
                        // copying backup db failed, bail
                        NSLog (@"couldn't init db");
                        return NULL;
                    }
                }
            }
    
    
            return dbFilePath;
    
        }
    

    Once you have copied the database file, you have its file path returned, and you use it to actually open the database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want to construct a data frame in an Rcpp function, but when I

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.