Adding Data

The NSEntityDescription class enables you to insert new objects into your context. This lets you add new data entries to populate your file. Provide an entity name and the context you’re working with:

// Create new object - (NSManagedObject *)newObject {     NSManagedObject *object = [NSEntityDescription         insertNewObjectForEntityForName:_entityName         inManagedObjectContext:_context];     return object; }

The request returns a new managed object for you to work with. After you receive the new managed object, you customize it however you like and then save the context:

// Save - (BOOL)save {     NSError __autoreleasing *error;     BOOL success;     if (!(success ...

Get The Core iOS Developer’s Cookbook, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.