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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:21:38+00:00 2026-05-16T12:21:38+00:00

My app is crashing when testing on the device, but not on the simulator.

  • 0

My app is crashing when testing on the device, but not on the simulator. It happens when I go to log out. I’m deleting all records from core data when the user logs out, code as follows:

-(IBAction)logOut
{
    UIAlertView *getConfirmation = [[UIAlertView alloc] initWithTitle:@"Confirm" message:@"Are you sure you want to logout. You will lose any unsync'ed workouts." delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Logout", nil];
    [getConfirmation show]; 
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 1){
        // Clear the database of all objects when the user logs out.
        [self deleteAllObjects:@"Workout"];
        [self deleteAllObjects:@"Route"];
        [self deleteAllObjects:@"WayPoint"];
        [self deleteAllObjects:@"Graphs"];
        [self deleteAllObjects:@"userSettings"];

        [self presentModalViewController:loginViewController animated:NO];
    }   
}


-(void)deleteAllObjects:(NSString *)entityDescription{
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:entityDescription inManagedObjectContext:managedObjectContext];
    [fetchRequest setEntity:entity];

    NSError *error;
    NSArray *items = [managedObjectContext executeFetchRequest:fetchRequest error:&error];
    [fetchRequest release];

    for (NSManagedObject *managedObject in items) {
        [managedObjectContext deleteObject:managedObject];
        NSLog(@"%@ object deleted", entityDescription);
    }

    if (![managedObjectContext save:&error]) {
        NSLog(@"Error deleting %@ - error:%@",entityDescription,error);
    }
}

It seems to be happening when the I log in and log out straight away. In this case there would be no objects on 4 of the 5 tables (note: userSettings would have 1 record).

Looking at the console the error message is ‘*** Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘This NSPersistentStoreCoordinator has no persistent stores. It cannot perform a save operation.”, looking at the debugger its happening on the line if (![managedObjectContext save:&error]).

I’m not quite sure why this is happening, there would be no records in the table ‘Workout’ at this point, therefore there would be nothing to delete. The simulator seems to handle this with no problems.

Details of the Persistent Store code:

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {

    if (persistentStoreCoordinator != nil) {
        return persistentStoreCoordinator;
    }

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

    NSError *error;
    persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]];
    if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:nil error:&error]) {
        // Handle error
    }    

    return persistentStoreCoordinator;
}

Any help would be much appreciated, I’m stuck on this one not and not sure where to go from here.

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

    As Martin stated your error seems to be centered around the NSPersistentStore issue. Handing that error instead of having a comment of // Handle error would be a very good first step. It is quite possible you are getting an error right there and ignoring it.

    In addition, on exit, if it is your goal to delete all data, there is an easier way.

    Tear down the Core Data stack (releasing the NSManagedObjectContext, NSPersistentStoreCoordinator and the NSManagedObjectModel) and then delete the SQLite file. On next launch, all data is gone.

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

Sidebar

Related Questions

My app needs to build a buffer from all the selected cells on a
An app I'm writing always crashes on a clients computer, but I don't get
My app uses a WebRequest at certain points to get pages from itself. This
My app (winforms .net 2.0 / vs2008) works fine on my dev machine but
My app will be full screen, but I am having trouble finding the document
My app is crashing when I navigate two view controllers in my application. For
My app is crashing when I try to post images in an HTTP request.
My app has many controls on its surface, and more are added dynamically at
My app is installed via NSIS. I want the installer to install the program
My app keeps track of the state of about 1000 objects. Those objects are

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.