Inherits from NSObject
Declared in CYCoreData.h
CYCoreData.m

Properties

bundleName

The name NSString of the bundle that contains the model file

@property (nonatomic, strong) NSString *bundleName

Discussion

Warning: If nil, CYCoreData is using the main bundle

Declared In

CYCoreData.h

dataBaseFile

The name NSString of the database file name that will get saved in the cache directory

@property (nonatomic, strong) NSString *dataBaseFile

Declared In

CYCoreData.h

isTest

If set to YES, CYCoreData uses an NSInMemoryStoreType and does not write data to sqlite file via NSSQLiteStoreType.

@property (nonatomic, assign) BOOL isTest

Discussion

@example Unit testing.

Declared In

CYCoreData.h

modelFile

The name NSString of the .xcdatamodeld in the bundle

@property (nonatomic, strong) NSString *modelFile

Declared In

CYCoreData.h

readContext

Returns NSManagedObjectContext of [CYCoreData liason].readContext private property. The concurrencyType is NSMainQueueConcurrencyType which means all fetched entities will be on the main runloop and suitable for view display.

@property (nonatomic, strong) NSManagedObjectContext *readContext

Return Value

NSManagedObjectContext of [CYCoreData liason].readContext

Discussion

Warning: It is not wise to change or save to this context directly. ONLY READ

Declared In

CYCoreData.h

Class Methods

configureModelUniqueIdentifier:ofDataType:withJSONSearchString:

Sets the keys for and type of unique indexer for NSManagedObjects. This key is used to fetch unique NSEntity in the database.

+ (void)configureModelUniqueIdentifier:(NSString *)uniquePropertyKey ofDataType:(UniqueObjectValueType)uniqueObjectValueType withJSONSearchString:(NSString *)jsonSearchPropertyKey

Parameters

uniquePropertyKey

NSString for the unique property key if the NSManagedObject; example @“uid”

uniqueObjectValueType

UniqueObjectValueType type of value the uniquePropertyKey is

jsonSearchPropertyKey

NSString the key the unique property will have on a JSON of for that object

Discussion

Warning: If called, must call before init.

Declared In

CYCoreData.h

configureUniqueIdentifier:

+ (void)configureUniqueIdentifier:(UniqueIdentiferStruct)uniqueIdentiferStruct

Parameters

`UniqueIdentiferStruct`

Predefined struct of the values passesd to configureModelUniqueIdentifier:ofDataType:withJSONSearchString:

Discussion

Warning: If called, must call before init.

Declared In

CYCoreData.h

liason

Return singleton instance of CYCoreData

+ (instancetype)liason

Return Value

Return singleton instance of CYCoreData

Discussion

Warning: Must call configureSqliteFileName:withModelFileName first.

Declared In

CYCoreData.h

readContext

Class method readContext which forwards to the [[CYCoreDataInstance liason] readContext] method

+ (NSManagedObjectContext *)readContext

Return Value

NSManagedObjectContext of [CYCoreDataInstance liason].readContext

Declared In

CYCoreData.h

reset

Class method reset which forwards to the [[CYCoreDataInstance liason] reset] *

+ (void)reset

Declared In

CYCoreData.h

saveAsynchronously

Class method saveAsynchronously which forwards to the [[CYCoreDataInstance liason] saveAsynchronously] *

+ (void)saveAsynchronously

Declared In

CYCoreData.h

saveContextAndWait:

Class method saveContextAndWait: which forwards to the [[CYCoreDataInstance liason] saveContextAndWait:] method

+ (void)saveContextAndWait:(BOOL)shouldWait

Parameters

shouldWait

BOOL to forward to the [[CYCoreDataInstance liason] saveContextAndWait:] method

Declared In

CYCoreData.h

saveSynchronously

Class method saveSynchronously which forwards to the [[CYCoreDataInstance liason] saveSynchronously] *

+ (void)saveSynchronously

Declared In

CYCoreData.h

temporaryWriteContext

Class method temporaryWriteContext which forwards to the [[CYCoreDataInstance liason] temporaryWriteContext] method

+ (NSManagedObjectContext *)temporaryWriteContext

Return Value

NSManagedObjectContext of [[CYCoreDataInstance liason] temporaryWriteContext]

Declared In

CYCoreData.h

Instance Methods

createStoreAndManagedObjectModel

Creates datebase from the model file

- (void)createStoreAndManagedObjectModel

Discussion

Warning: Must be called to user CYCoredata funcationality

Declared In

CYCoreData.h

initWithSqliteFileName:withModelFileName:

Configures the file name for the .sqlite saved in the NSCachesDirectory. Tells CYCoreData the name of the *.xcdatamodeld to use and assumes it is located in the main bundle

- (id)initWithSqliteFileName:(NSString *)dataBaseFileName withModelFileName:(NSString *)modelFileName

Parameters

dataBaseFileName

NSString of the database file name that will get saved in the cache directory

withModelFileName

NSString of the .xcdatamodeld in the bundle

Declared In

CYCoreData.h

initWithSqliteFileName:withModelFileName:inBundleName:

Configures the file name for the .sqlite saved in the NSCachesDirectory. Tells CYCoreData the name of the *.xcdatamodeld to use and what bundle to search for it in

- (id)initWithSqliteFileName:(NSString *)dataBaseFileName withModelFileName:(NSString *)modelFileName inBundleName:(NSString *)bundleName

Parameters

dataBaseFileName

NSString of the database file name that will get saved in the cache directory

bundleName

NSString of the bundle name that contains the modelfile

withModelFileName

NSString of the .xcdatamodeld in the bundle

Discussion

Warning: Do not use if .xcdatamodeld is in the mainbundle.

Declared In

CYCoreData.h

reset

Empties database of all entities, destroys NSManagedObject model and NSPersistantStoreCoordinator.

- (void)reset

Discussion

Warning: Does not reset config class variables.

Declared In

CYCoreData.h

saveAsynchronously

Calls a Asychronous(performBlock) action to the top NSManagedObjectContext to write the changes to disk.

- (void)saveAsynchronously

Discussion

@example Call when ever sychronous behavior is not desired.

Declared In

CYCoreData.h

saveContextAndWait:

For topLevelContext performBlockAndWait pass YES. For topLevelContext performBlock pass NO.

- (void)saveContextAndWait:(BOOL)andWait

Parameters

andWait

BOOL for identify call to topLevelContext performBlock or performBlockAndWait

Declared In

CYCoreData.h

saveSynchronously

Calls a sychronous(performBlockAndWait) action to the top NSManagedObjectContext to write the changes to disk.

- (void)saveSynchronously

Discussion

@example Call when app terminates or goes in to background.

Declared In

CYCoreData.h

temporaryWriteContext

Returns a brand NSManagedObjectContext of spawned off of the [CYCoreData readContext]. To update the database, fetch the NSEntityDescriptions from this context, create or modify as you see fit. When finished, immediately call either [temporaryWriteContext saveSynchronously] or [temporaryWriteContext saveAsynchronously]. This ensures that the changes will be pushed up to the [CYCoreData readContext], then written to disk.

- (NSManagedObjectContext *)temporaryWriteContext

Return Value

NSManagedObjectContext of [CYCoreData liason].readContext

Discussion

Warning: It is not wise to change or save to this context directly. ONLY READ

Declared In

CYCoreData.h