NSManagedObjectContext(ETCoreData) Category Reference
Declared in | ETCoreData.h |
Overview
NSManagedObjectContext (ETCoreData)
is a helper category that provides easier and better helper methods to manage NSManagedObjectContext
objects.
Instance Methods
allObjectsOfType:
Returns all the NSManagedObject
objects whose entity name matches the one provided.
- (NSArray *)allObjectsOfType:(NSString *)entityName
Parameters
- entityName
The name of the
NSManagedObject
entities to be queried.
Return Value
A NSArray
containing all the NSManagedObject
on the local database.
Declared In
ETCoreData.h
countObjectsOfType:withPredicate:
Executes the query with the provided NSPredicate
for the NSManagedObject
whose entity name matches the NSString
entity name provided.
- (int)countObjectsOfType:(NSString *)entityName withPredicate:(NSPredicate *)predicate
Parameters
- entityName
The entity name of the
NSManagedObject
entities to be queried.
- predicate
The
NSPredicate
that will be used to filter the query.
Return Value
The count of NSManagedObject
whose entity name matches entityName
and fulfills the provided predicate
.
Discussion
Internally calls fetchObjectsOfType:withPredicate:andSortDescriptors:
in order to fulfill the initial query.
Declared In
ETCoreData.h
deleteObjects:
Iterates throught the list of NSManagedObject
provided and calls deleteObject:
for each one. Then calls submitChanges
;
- (void)deleteObjects:(NSArray *)objects
Parameters
- objects
A
NSArray
ofNSManageObject
that will be iterated to call-deleteObject:
on it.
See Also
Declared In
ETCoreData.h
deleteObjectsOfType:withPredicate:
Calls fetchObjectsOfType:withPredicate:andSortDescriptors:
with the provided entity name and NSPredicate
; then calls deleteObjects:
with the resulting NSArray
.
- (void)deleteObjectsOfType:(NSString *)entityName withPredicate:(NSPredicate *)predicate
Parameters
- entityName
The entity name of the
NSManagedObject
entity
- predicate
The
NSPredicate
that will be used to filter the query.
Declared In
ETCoreData.h
fetchObjectsOfType:withPredicate:andSortDescriptors:
Executes the provided NSPredicate
on the NSManagedObject
whose entity name matches the one provided sorted by the provided NSArray
of NSSortDescriptor
.
- (NSArray *)fetchObjectsOfType:(NSString *)entityName withPredicate:(NSPredicate *)predicate andSortDescriptors:(NSArray *)sortDescriptors
Parameters
- entityName
The name of the
NSManagedObject
entities to be queried.
- predicate
The
NSPredicate
that will be used to filter the query.
- sortDescriptors
A
NSArray
containingNSSortDescriptor
objects that will be used to query the database.
Return Value
A NSArray
of NSManagedObject
that matches the provided predicate
.
Declared In
ETCoreData.h
fetchSingleObject:withPredicate:
Fetches a single object for the NSManagedObject
whose entity name matches the one provided and fulfills the provided NSPredicate
.
- (id)fetchSingleObject:(NSString *)entity withPredicate:(NSPredicate *)predicate
Parameters
- entity
The name of the
NSManagedObject
entities to be queried.
- predicate
The
NSPredicate
that will be used to filter the query.
Return Value
The first NSManagedObject
that matches the provided predicate
on a NSManagedObject
whose entity name matches the one provided.
Declared In
ETCoreData.h
hasEntityWithId:idColumn:identifier:
Checks if there’s a NSManagedObject
in the database whose idColumn
matches the provided NSString
identifier.
- (BOOL)hasEntityWithId:(NSString *)entityName idColumn:(NSString *)idColumn identifier:(NSString *)identifier
Parameters
- entityName
The name of the
NSManagedObject
entities to be queried.
- idColumn
The name of the column to be used to query looking for the provided identifier.
- identifier
The
NSString
object that will be used as the key for searching anNSManagedObject
.
Return Value
YES
if there’s a NSManagedObject
that contains the provided identifier
on the selected idColumn
, NO
otherwise.
Declared In
ETCoreData.h
scalarExpressionValueForColumn:expression:entity:withPredicate:
Executes the NSExpression
associated to the provided kPredefinedExpression
enum value to the column provided on the NSManagedObject
whose entity name matches the one provided that also fulfills the NSPredicate
provided.
- (int)scalarExpressionValueForColumn:(NSString *)column expression:(kPredefinedExpression)predefinedExpression entity:(NSString *)entity withPredicate:(NSPredicate *)predicate
Parameters
- column
The name of the column to be used as the field to execute the
NSExpression
.
- predefinedExpression
The
kPredefiendExpression
enum value to be used when building theNExpression
,
- entity
The name of the
NSManagedObject
entities to be queried.
- predicate
The
NSPredicate
that will be used to filter the query.
Return Value
The int
resulting of executing the NSExpression
to the to the column provided on the NSManagedObject
with the provided entity name that satisfies the provided NSPredicate
.
Discussion
This method internally calls fetchObjectsOfType:withPredicate:andSortDescriptors:
to fulfill the provided filtering details.
Declared In
ETCoreData.h