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");
}
}
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.