Book Image

Objective C Memory Management Essentials

Book Image

Objective C Memory Management Essentials

Overview of this book

Table of Contents (18 chapters)
Objective-C Memory Management Essentials
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Saving data into the persistent store


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];
  ...