NSManagedObjectContext(RKAdditions) Category Reference
Declared in | NSManagedObjectContext+RKAdditions.h |
Tasks
Inserting a Managed Object
-
– insertNewObjectForEntityForName:
Inserts a new managed object for the entity for the given name.
Counting Managed Objects
-
– countForEntityForName:predicate:error:
Convenience method for performing a count of the number of instances of an entity with the given name.
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:
Convenience method for performing a count of the number of instances of an entity with the given name.
- (NSUInteger)countForEntityForName:(NSString *)entityName predicate:(NSPredicate *)predicate error:(NSError **)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.
Discussion
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];
Declared In
NSManagedObjectContext+RKAdditions.h
insertNewObjectForEntityForName:
Inserts a new managed object for the entity for the given name.
- (id)insertNewObjectForEntityForName:(NSString *)entityName
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.
Discussion
This method is functionally equivalent to the follow code example.
[NSEntityDescription insertNewObjectForEntityForName:entityName inManagedObjectContext:self];
Declared In
NSManagedObjectContext+RKAdditions.h
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.
- (BOOL)saveToPersistentStore:(NSError **)error
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