To do a successful save using Core Data, you require:
NSManagedObject
NSManagedObjectContext
NSPersistentStoreCoordinator
NSManagedObjectModel
So, in our screen that saves these variables into our Customer
entity, the following code fragment does all the magic for the (IBAction)save:(id)sender
method. This will enable us to save our data from a new customer or update an existing customer's information:
- (IBAction)save:(id)sender { if ([nameTxtField text].length == 0) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Name must not be empty" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; return; } NSString *name = [nameTxtField text]; NSString *phone = [phoneTxtField text]; NSString *email = [emailTxtField text]; NSString *address = [addressTxtField text]; int age = [[ageTxtField text] intValue]; ...