ETCoreDataStore Class Reference
Inherits from | NSObject |
Declared in | ETCoreData.h |
Overview
Wrapper that manages the NSManagedObjectModel
, NSManagedObjectContext
& NSPersistentStoreCoordinator
for a local database
Tasks
Definition properties
-
dataFilePath
property -
managedObjectModel
property -
managedObjectContext
property -
persistentStoreCoordinator
property
Initialization
Manipulation methods
Formatters
Handling
Store manipulation
-
– insertObjectFromJson:entityName:dateFormatter:
-
– insertObjectFromJson:entityName:
-
– updateObjectFromJson:entityName:
-
– updateObjectFromJson:entityName:identifierKey:dateFormatter:
-
– updateObjectFromJson:entityName:predicate:dateFormatter:
-
– addObjectsFromJsonArray:addSingleSelector:
Other methods
Properties
dataFilePath
The local path for the NSManagedObjectModel
object.
@property (nonatomic, retain) NSString *dataFilePath
Declared In
ETCoreData.h
managedObjectContext
The NSManagedObjectContext
linked to persistentStoreCoordinator
.
@property (nonatomic, retain) NSManagedObjectContext *managedObjectContext
Declared In
ETCoreData.h
managedObjectModel
The NSManagedObjectModel
created with the dataFilePath
.
@property (nonatomic, retain) NSManagedObjectModel *managedObjectModel
Declared In
ETCoreData.h
persistentStoreCoordinator
The NSPersistentStoreCoordinator
that handles the managedObjectModel
.
@property (nonatomic, retain) NSPersistentStoreCoordinator *persistentStoreCoordinator
Declared In
ETCoreData.h
Instance Methods
addObjectsFromJsonArray:addSingleSelector:
Adds all the JSON
objects from the provided jsonArray
via executing addSingleSelector
on each one of them.
- (NSSet *)addObjectsFromJsonArray:(id)jsonArray addSingleSelector:(SEL)addSingleSelector
Parameters
- jsonArray
The
JSON
array containing theJSON
objects that will be added to the database.
- addSingleSelector
The specific
selector
that will be called with each object as a paramter to be added to the database.
Return Value
A NSSet
containing all the NSManagedObject
added to the database.
Declared In
ETCoreData.h
cancelChanges
Calls the reset
method of the managedObjectContext
.
- (void)cancelChanges
Declared In
ETCoreData.h
clearDatabase
Iterates through the list of NSManagedObject
on the local database and calls deleteObjectsOfType:withPredicate
on managedObjectContext
.
- (void)clearDatabase
Discussion
// @see NSManagedObjectContext deleteObjectsOfType:withPredicate
// The @see statement was removed because appledoc can’t find the crossreference
Declared In
ETCoreData.h
hasFileBeenProcessed:
Checks whether or not the file at provided has been processed.
- (BOOL)hasFileBeenProcessed:(NSString *)fileName
Parameters
- fileName
The name of the file to be checked.
Return Value
YES
if the file with name fileName
has been processed, NO
otherwise.
See Also
Declared In
ETCoreData.h
identifierPredicate:
Generates an NSPredicate
with the provided identifier.
- (NSPredicate *)identifierPredicate:(id)identifier
Parameters
- identifier
The identifier to be passed on the newly created
NSPredicate
object.
Return Value
A NSPredicate
generated by calling [NSPredicate predicateWithFormat:@"identifier = %@", identifier]
.
Declared In
ETCoreData.h
initWithDataFile:
Initializes the dataFilePath
and then creates all the related objects (managedObjectModel
, managedObjectContext
& persistentStoreCoordinator
) based on that.
- (id)initWithDataFile:(NSString *)dataFilePath
Parameters
- dataFilePath
The file path pointing to the
NSManagedObjectModel
.
Return Value
A fully initialized ETCoreDataStore
object.
Declared In
ETCoreData.h
insertObjectFromJson:entityName:
Creates a new NSManagedObject
whose name matches the provided entity name; filled with provided JSON
dictionary.
- (id)insertObjectFromJson:(id)jsonDictionary entityName:(NSString *)entityName
Parameters
- jsonDictionary
The
JSON
dictionary that will be used to populate the newly createdNSManagedObject
entity.
- entityName
The
NSString
describing the entity name of theNSManagedObject
instance.
Return Value
A newly created NSManagedObject
pre-populated with the provided JSON
dictionary.
Discussion
This method internally calls insertObjectFromJson:entityName:dateFormatter:
with jsonDateFormatter
as the NSDateFormatter
.
Declared In
ETCoreData.h
insertObjectFromJson:entityName:dateFormatter:
Creates a new NSManagedObject
whose name matches the provided entity name; filled with provided JSON
dictionary. The provided NSDateFormatter
is used to format the NSDate
objects found on the jsonDictionary
.
- (id)insertObjectFromJson:(id)jsonDictionary entityName:(NSString *)entityName dateFormatter:(NSDateFormatter *)dateFormatter
Parameters
- jsonDictionary
The
JSON
dictionary that will be used to populate the newly createdNSManagedObject
entity.
- entityName
The
NSString
describing the entity name of theNSManagedObject
instance.
- dateFormatter
The
NSDateFormatter
that will be used to format theNSDate
objects found on theJSON
dictionary provided.
Return Value
A newly created NSManagedObject
pre-populated with the provided JSON
dictionary.
Declared In
ETCoreData.h
jsonDateFormatter
Returns a caching NSDateFormatter
with UTC NSTimeZone
and the following format: @"en_US_POSIX"
- (NSDateFormatter *)jsonDateFormatter
Return Value
A NSDateFormatter
with UTC NSTimeZone
and @"en_US_POSIX"
format.
Declared In
ETCoreData.h
markFileAsProcessed:
Marks the file with name fileName
as processed.
- (void)markFileAsProcessed:(NSString *)fileName
Parameters
- fileName
The name of the file to be marked as checked.
See Also
Declared In
ETCoreData.h
submitChanges
Calls the submitChanges
method on managedObjectContext
.
- (void)submitChanges
Discussion
// @see NSManagedObjectContext+(ETCoreData) deletedObjectsOfType:withPredicate
// The @see statement was removed because appledoc can’t find the crossreference
Declared In
ETCoreData.h
updateObjectFromJson:entityName:
Updates a NSManageObject
instance whose entity name matches the one provided. The properties are set with the provided JSON
dictionary and KVO
.
- (id)updateObjectFromJson:(id)jsonDictionary entityName:(NSString *)entityName
Parameters
- jsonDictionary
The
JSON
dictionary that will be used to update theNSManagedObject
entity retrieved from the database.
- entityName
The
NSString
describing the entity name of theNSManagedObject
instance.
Return Value
A NSManagedObject
instance fetched from the database whose properties are updated with the provided JSON
dictionary.
Discussion
This method calls internally updateObjectFromJson:entityName:identifierKey:dateFormatter:
with jsonDateFormatter
as the NSDateFormatter
.
Declared In
ETCoreData.h
updateObjectFromJson:entityName:identifierKey:dateFormatter:
Updates a NSManageObject
instance whose entity name matches the one provided. The properties are set with the provided JSON
dictionary and KVO
.
The provided NSDateFormatter
is used to format the NSDate
objects found on the jsonDictionary
.
- (id)updateObjectFromJson:(id)jsonDictionary entityName:(NSString *)entityName identifierKey:(NSString *)identifierKey dateFormatter:(NSDateFormatter *)dateFormatter
Parameters
- jsonDictionary
The
JSON
dictionary that will be used to update theNSManagedObject
entity retrieved from the database.
- entityName
The
NSString
describing the entity name of theNSManagedObject
instance.
- identifierKey
The name of the unique identifier column/property that will be used to fetch an
NSManagedObject
instance from the database.
- dateFormatter
The
NSDateFormatter
that will be used to format theNSDate
objects found on theJSON
dictionary provided.
Return Value
A NSManagedObject
instance fetched from the database whose properties are updated with the provided JSON
dictionary.
Discussion
This method internally calls updateObjectFromJson:entityName:predicate:dateFormatter:
in order to fetch the correct entity from the database.
Declared In
ETCoreData.h
updateObjectFromJson:entityName:predicate:dateFormatter:
Updates a NSManagedObject
instance whose entity name matches the one provided as well as the predicate provided. The properties are set with the provided JSON
dictionary and KVO
.
The provided NSDateFormatter
is used to format the NSDate
objects found on the jsonDictionary
.
- (id)updateObjectFromJson:(id)jsonDictionary entityName:(NSString *)entityName predicate:(NSPredicate *)predicate dateFormatter:(NSDateFormatter *)dateFormatter
Parameters
- jsonDictionary
The
JSON
dictionary that will be used to update theNSManagedObject
entity retrieved from the database.
- entityName
The
NSString
describing the entity name of theNSManagedObject
instance.
- predicate
The
NSPredicate
that will be used to fetch and filter the correctNSManagedObject
instance to be formatted.
- dateFormatter
The
NSDateFormatter
that will be used to format theNSDate
objects found on theJSON
dictionary provided.
Return Value
A NSManagedObject
instance fetched from the database whose properties are updated with the provided JSON
dictionary.
Declared In
ETCoreData.h