0

I am new to iOS development so please bear with me. I have created an application that uses the CoreData framework and I have been following the tutorial on Apple's website. I have an AppDelegate file with the Context, Object, and the PersistantStore. A RootViewController, and a SubViewController that the RootViewController calls on with a Context and a fetchedResultsController. In my ModelData I have 4 string attributes which I use to store basic user information regarding their session.

What I am trying to do is when the user exits the program their past information gets removed and the new information is to be saved. I just want 1 entry saved at all times. The issue is that when I get to the save I get a SIGABRT being thrown for some reason. When I placed a try catch around the save then I am able to see the data the next time I try a save. However, when I restart the application the session information is no longer there.

Is there any good advice that anyone can bestow on me?

EDIT

-(void)UpdateSession
{
    // Delete all records
    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Session" inManagedObjectContext:managedObjectContext];
    [request setEntity:entity];

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

    // Create and store a new session
    Session *newSession = (Session *)[NSEntityDescription insertNewObjectForEntityForName:@"Session" inManagedObjectContext:managedObjectContext];

    // Set the data
    [newSession setMap:@"TestMap"];
    [newSession setLayout:@"Top"];
    [newSession setSpeed:@"3"];
    [newSession setCamera:@"1"];
    error = nil;

    if(![managedObjectContext save:&error])
    {
        NSLog("Error");
    }
}
Seb
  • 3,414
  • 10
  • 73
  • 106
  • Can you add your code?So that we can understand what u did... – Dinesh Raja Jan 18 '12 at 17:38
  • also post the full error message. core data will fail on a save if there is an inconsistency in the data. – Damo Jan 18 '12 at 17:50
  • I've added the function of where I delete and save my data. @Damo I am not seeing any error messages in my output window. I just get sent back into my application's main funtion with a green popup saying that "Program received signal: "SIGABRT" – Seb Jan 18 '12 at 17:55
  • enable all breakpoints and see where the exception is thrown. check this [stackoverflow topic](http://stackoverflow.com/questions/4961770/run-stop-on-objective-c-exception-in-xcode-4) – Lorenzo B Jan 18 '12 at 18:04
  • The exception is thrown in the save function. However the only error message I get is Catchpoint 12 (exception thrown) – Seb Jan 18 '12 at 18:12

2 Answers2

0

I found this SO question. Something for you to check. Do you have any NSFetchedResultsController's anywhere which may be reacting to the context save?

This SO is related but essentially in both answers there is something reacting to the moc save and trying to talk to a delegate method that it shouldn't do.

Community
  • 1
  • 1
Damo
  • 12,840
  • 3
  • 51
  • 62
0

I figured out the answer after looking at other core data tutorials. What was weird is that I had to create a local copy of the database and then move it over into the iOS application and that seemed to work. Which is odd since the iOS application should create the store file and read and write directly from it. Not sure if it was an issue with permissions or what not, but it seems that all is able to run properly.

Seb
  • 3,414
  • 10
  • 73
  • 106