Declared in NSManagedObjectContext+RKAdditions.h

Overview

Provides extensions to NSManagedObjectContext for various common tasks.

Tasks

Inserting a Managed Object

Counting Managed Objects

Saving the Context to the Persistent Store

  • – saveToPersistentStore:

    Saves the receiver and then traverses up the parent context chain until a parent managed object context with a nil parent is found. If the final ancestor context does not have a reference to the persistent store coordinator, then a warning is generated and the method returns NO.

Instance Methods

countForEntityForName:predicate:error:

- (NSUInteger)countForEntityForName:(NSString *)entityName predicate:(NSPredicate *)predicate error:(NSError **)error
Discussion

Convenience method for performing a count of the number of instances of an entity with the given name.

This method is functionally equivalent to the following code example.

NSError *error;
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:entityName];
fetchRequest.predicate = predicate;
NSUInteger count = [managedObjectContext countForFetchRequest:fetchRequest error:&error];

Parameters

entityName

The name of an entity.

predicate

A predicate to limit the search. May be nil.

error

If there is a problem executing the fetch, upon return contains an instance of NSError that describes the problem.

Return Value

The number of objects a fetch request for the given entity name with the given predicate would have returned if it had been passed to executeFetchRequest:error:, or NSNotFound if an error occurs.

Declared In

NSManagedObjectContext+RKAdditions.h

insertNewObjectForEntityForName:

- (id)insertNewObjectForEntityForName:(NSString *)entityName
Discussion

Inserts a new managed object for the entity for the given name.

This method is functionally equivalent to the follow code example.

[NSEntityDescription insertNewObjectForEntityForName:entityName inManagedObjectContext:self];

Parameters

entityName

The name of an entity.

Return Value

A new, autoreleased, fully configured instance of the class for the entity named entityName. The instance has its entity description set and is inserted into the receiver.

Declared In

NSManagedObjectContext+RKAdditions.h

saveToPersistentStore:

- (BOOL)saveToPersistentStore:(NSError **)error
Discussion

Saves the receiver and then traverses up the parent context chain until a parent managed object context with a nil parent is found. If the final ancestor context does not have a reference to the persistent store coordinator, then a warning is generated and the method returns NO.

Parameters

error

If there is a problem saving the receiver or any of its ancestor contexts, upon return contains an pointer to an instance of NSError that describes the problem.

Return Value

YES if the save to the persistent store was successful, else NO.

Declared In

NSManagedObjectContext+RKAdditions.h