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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:48:32+00:00 2026-05-21T11:48:32+00:00

CD’s been an enormous learning curve for me and there’s still a bit for

  • 0

CD’s been an enormous learning curve for me and there’s still a bit for me to go, but any help on the following could enable me to lift the current weight on my shoulders!

I’m trying to write a method that implements a “Save As..” for the user in my CD app.

So far I’ve got:

[saveAsPanel beginSheetModalForWindow:window completionHandler:^(NSInteger userResult)
{
if (userResult == NSOKButton) {
    NSPersistentStoreCoordinator *psc = [self persistentStoreCoordinator];
    NSURL *oldURL = [self URLOfInternalStore]; //returns the current store's URL
    NSURL *newURL = [saveAsPanel URL];
    NSError *error = nil;
    NSPersistentStore *oldStore = [psc persistentStoreForURL:oldURL];
    NSPersistentStore *sqLiteStore = [psc migratePersistentStore:oldStore
                                                           toURL:newURL
                                                         options:nil
                                                        withType:NSXMLStoreType
                                                           error:&error];
}
}];

Unfortunately, I just get the error:

Object’s persistent store is not reachable from this NSManagedObjectContext’s coordinator.

Should I ‘remove’ and then ‘addPersistentStore…’ to update it to the new URL? The doc’s seem to suggest that all will be handled with in the ‘migrate’ method.

Thanks in advance!

Edit:

Ok, well, I’ve come up with my own ‘dirty’ method. I can imagine that this isn’t an approved way of doing things, but there’s no error thrown up and the app works as expected at all times (not often I can say that, either!):

        -(IBAction)saveAsAction:(id)sender
    {
        NSSavePanel *saveAsPanel = [NSSavePanel savePanel];
        [saveAsPanel beginSheetModalForWindow:window completionHandler:^(NSInteger userResult)
        {
        if (userResult == NSOKButton) {
            [self saveAction:@"saveAsCalling"];
            NSURL *newURL = [saveAsPanel URL];
            NSError *error = nil;
            [[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:internalStore] toURL:newURL error:&error];
//internalStore is a hard-wired NSString that holds the path to the bundle's database
        }
        }];
    }

    -(IBAction)loadAction:(id)sender
    {
        NSOpenPanel *loadPanel = [NSOpenPanel openPanel];
        [loadPanel beginSheetModalForWindow:window completionHandler:^(NSInteger userResult)
         {
             if (userResult == NSOKButton) {
                 [self saveAction:@"loadCalling"];
                 NSURL *newURL = [loadPanel URL];
                 NSURL *oldURL = [NSURL fileURLWithPath:internalStore];
                 NSError *error = nil;
                 NSPersistentStoreCoordinator *psc = [SELF_MOC persistentStoreCoordinator];
                 [psc removePersistentStore:[[self persistentStoreCoordinator] persistentStoreForURL:oldURL] error:&error];
                 [psc addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:newURL options:nil error:&error];
                 [[NSFileManager defaultManager] removeItemAtURL:oldURL error:&error];
                 [[NSFileManager defaultManager] copyItemAtURL:newURL toURL:oldURL error:&error];
                 [psc removePersistentStore:[[self persistentStoreCoordinator] persistentStoreForURL:newURL] error:&error];
                 [psc addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:oldURL options:nil error:&error];
             }
         }];
    }

The basic reasoning is this: to do a ‘SaveAs…’ I simply copy out the SQLLite store file in the mainBundle to wherever the user selects and rename it to what they want – as per TechZen’s suggestion.

To do a ‘Load’ then I first removePersistentStore from the bundle’s file, add the one that the user’s just chosen. Delete the bundle store (which in theory isn’t now being used) and then copy the user’s choice back into the bundle. Finally, the two operations of remove and addPersistentStore are performed to point the app back to it’s bundle’s file which is now the user’s choice.

Hope that makes sense. If anyone has any thoughts on just how unprofessional a methodology this is then please – be kind as I’m fairly new – let me know. I can’t find anything that is more elegant.

I know Apple don’t like you using removePersistentStore and addPersistentStore but, as I say no errors are reported (in my actual code I scattered NSLog lines throughout to report what error is holding).

  • 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-21T11:48:33+00:00Added an answer on May 21, 2026 at 11:48 am

    You only use a SaveAs... in a document based app. If you use Core Data as your model, you need to use NSPersistentDocument to save your data. It provide the SaveAs... functionality you seek.

    Straight Core Data is used for more database-like apps in which the entire app operates from one data set (more or less.)

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

Sidebar

Related Questions

This could be a duplicate question, but I have no idea what search terms
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
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 know there's a lot of other questions out there that deal with this
I have been unable to fix a problem with Java Unicode and encoding. 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.