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

Updating data


Finally, to update a record, it is much simpler than you think, thanks to the abstraction layer. To update data, we just assign the values to our customer object in the (IBAction)save:(id)sender method, which you saw earlier:

if (customer)//if we showing existing customer data
{
        NSNumber *age = [NSNumber numberWithInt:[[ageTxtField text] intValue]];
        [customer setValue:[nameTxtField text] forKey:@"name"];
        [customer setValue:age forKey:@"age"];
        [customer setValue:[addressTxtField text] forKey:@"address"];
        [customer setValue:[emailTxtField text] forKey:@"email"];
        [customer setValue:[phoneTxtField text] forKey:@"phone_number"];
    }

We will add the following code after we set the values of our customer object:

NSError *error = nil;
    // Save the object to persistent store
    NSString *str;
    if (![context save:&error]) {
        str = [NSString stringWithFormat:@"Error saving %@ with localized description %@", error, [error...