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 7615147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:34:48+00:00 2026-05-31T02:34:48+00:00

I am using UIManagedDocument’s Context to interact with my Core Data Model. However, I

  • 0

I am using UIManagedDocument’s Context to interact with my Core Data Model. However, I would like to initially load the Persistant Store contact from a local sqlite database that I have. I believe I am supposed to use configurePersistentStoreCoordinatorForURL: but have no idea how to do it. All I found on the Apple store was an example with App Delegate Core Data not this function or UIManagedDocument way.
My source sqlite database in resource folder is called source_from.sqlite and the Data model is called Source.xcdatamodeld

Also I prefer to have the new sqlite db in the document package. Not sure if the migration will happen automatically?

Thanks for your help,

Ross

Here is what I have and planning to do it in the initialize method:

-(void) initializeSourceDatabaseWithData:(UIManagedDocument *) sourceDatabase{
  // if no persistent store for the uidocument preload it 
  // from sqlite file
}

-(void) useDocument{
    if (![[NSFileManager defaultManager] fileExistsAtPath:[self.sourceDatabase.fileURL path]]){
        [self.sourceDatabase saveToURL:self.sourceDatabase.fileURL forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success){
            [self setupFetchedResultController]; 
            [self initializeSourceDatabaseWithData:self.sourceDatabase];

         }];
    }else if (self.sourceDatabase.documentState == UIDocumentStateClosed){
        [self.sourceDatabase openWithCompletionHandler:^(BOOL success){
         [self setupFetchedResultController];   
        }];
    }else if(self.sourceDatabase.documentState == UIDocumentStateNormal){
        [self setupFetchedResultController];

    }
}

-(void) setSourceDatabase:(UIManagedDocument *)sourceDatabase{
    if (sourceDatabase != _sourceDatabase){
        sourceDatabase = _sourceDatabase;
        [self useDocument];
    }
}

-(void) viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];

    if (!self.sourceDatabase){
        NSURL * url = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
        url = [url URLByAppendingPathComponent:@"Source Database"];
        self.sourceDatabase = [[UIManagedDocument alloc] initWithFileURL:url];
    }
}
  • 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-31T02:34:49+00:00Added an answer on May 31, 2026 at 2:34 am

    I believe the best way is to subclass UIManagedDocument Class and implement the PersistanceStoreConfiguration so that it loads the file from outside the document package.

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

Sidebar

Related Questions

I am using Core Data for the first time and was just curious if
Using Rails 3.2.0 with haml and sass: I Would like to link an external
using xmltextreader, how would I load a hashtable. XML: <base><user name=john>2342343</user><user name=mark>239099393</user></base> This was
My app uses a UIManagedDocument to handle its data with Core Data. There's a
Using Ninject i would like to rebind one method to another implementation is that
Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters
Using preview 4 of ASP.NET MVC Code like: <%= Html.CheckBox( myCheckBox, Click Here, True,
So this sucks. Trying to populate a core data database with info from NSDictionaries.
I have created a core data database in one application which involved sucking out
Using Android TelephonyManager an application can obtain the state of data activity over the

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.