I’ve programmed a button to take the text in my text fields and store them into an entity. When I run in the iPhone simulator, enter in some text, and press the button, it crashes. There aren’t messages that show me what’s going on. I’ve determined that it’s this uncommented line of code that the simulator is not liking:
Person *person = [NSEntityDescription insertNewObjectForEntityForName:@"Person" inManagedObjectContext:self.managedObjectContext];
// person.username = self.usernameTextField.text;
// person.password = self.passwordTextField.text;
// person.carmodel = self.carModelTextField.text;
// [self.managedObjectContext save:nil];
Any ideas on what could be happening? I don’t even know where to start. The compiler of course is not giving problems because simulator runs. Thanks in advance!
this problem might be caused by more than one reason ! please supply the exception log in Xcode you will find it in the output section ( View -> Debug area -> Activate Console )
here’s what might be causing the crash !
you’ve altered your data model ( after altering your data model you have to delete the app from simulator/device and install it again )
there might be a typo in the entity name “Person” in the line of code you provided check that it matches the entity name in your data model.
your managedObjectContext is not initialized, if this is not the main view controller of your app you have to pass the managedObjectContext to it. first make sure that the app delegate managedObjectContext is properly set , and you are passing in around from one view controller to the other.