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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:25:24+00:00 2026-06-18T09:25:24+00:00

I am using coreData, with one -to-many realtionship, I have a folder entity and

  • 0

I am using coreData, with one -to-many realtionship, I have a folder entity and a file entity. A folder can have many files and so on.

So, I have two ViewControllers, FolderViewController and FileViewController which contains folders and files respectively.Now I have a modalView , which is accesible from both folder and file viewcontroller. In this VC I have a button to Reset all Data. So when I click this I want all the data should reset.

I used this code,this function is written in appdelegate.m and called from my VC.

- (void)resetToDefault
{
    NSError * error;
    // retrieve the store URL
    NSURL * storeURL = [[__managedObjectContext persistentStoreCoordinator] URLForPersistentStore:[[[__managedObjectContext persistentStoreCoordinator] persistentStores] lastObject]];
    // lock the current context
    [__managedObjectContext lock];
    [__managedObjectContext reset];//to drop pending changes
    //delete the store from the current managedObjectContext
    if ([[__managedObjectContext persistentStoreCoordinator] removePersistentStore:[[[__managedObjectContext persistentStoreCoordinator] persistentStores] lastObject] error:&error])
    {
        // remove the file containing the data
        [[NSFileManager defaultManager] removeItemAtURL:storeURL error:&error];
        //recreate the store like in the  appDelegate method
        [[__managedObjectContext persistentStoreCoordinator] addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error];//recreates the persistent store
    }
    [__managedObjectContext unlock];
    //that's it !

    NSLog(@"buttonReset Pressed");
}

So after clicking on resetButton when I close the View, I get this error

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Object's persistent store is not reachable from this NSManagedObjectContext's coordinator'

So how to solve this.

Regards
Ranjit

  • 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-06-18T09:25:25+00:00Added an answer on June 18, 2026 at 9:25 am

    I have solved this problem, below is the code,

    This function has been written in appdelegate.m

    - (void) resetApplicationModel
    {
        NSError *error;
        NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"AppName.sqlite"];
        [[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil];
        for (NSManagedObject *ct in [self.managedObjectContext registeredObjects]) {
            [self.managedObjectContext deleteObject:ct];
        }
    
        //Make new persistent store for future saves   
        if (![self.persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
            // do something with the error
        }  
    }
    

    And in my SettingsViewController, I am calling this on resetbutton clicked in this way.

    - (void)resetButtonclicked
    {
    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
            [appDelegate resetApplicationModel];  
    }  
    

    Regards
    Ranjit.

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

Sidebar

Related Questions

I have a one (troop) to many (members) relationship using core data. I can
So, I've got a one-to-many relationship of Companies to Employees in CoreData (using a
I have two entities in core data with one to many relationship between them
Given and coredata based app using an Indexcard metaphor. Each Indexcard can optionally have
I have a Department entity which has a one-to-many relationship to an Employee entity.
In my app, Im using CoreData and I have two entities. VenueInfo and ContactInfo.
I am using CoreData in my application and it is a one-to-many relationship, I
I am using core data and set up a one to many relationship for
I have a sample app using CoreData, and am now ready to convert my
Currently I have one managedContext, many NSArrayControllers of entities which are all pretty interrelated,

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.