Inherits from NSObject
Declared in OCRCoreDataController.h
OCRCoreDataController.m

Overview

Singleton object to manage the data store for KOResume

Properties

managedObjectContext

Returns the managed object context for the application.

@property (nonatomic, strong, readonly) NSManagedObjectContext *managedObjectContext

Discussion

If the context doesn’t already exist, it is created and bound to the persistent store coordinator for the app. See: Using Core Data with iCloud and Ray Wenderlich’s Core Data Tutorial for excellent tutorials on this setting up core data/iCloud

Declared In

OCRCoreDataController.h

persistentStoreCoordinator

The NSPersistentStoreCoordinator for the KOResume database

@property (nonatomic, strong, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator

Declared In

OCRCoreDataController.m

Instance Methods

addStore:withOptions:

Add a persistent store to the NSPersistentStoreCoordinator

- (BOOL)addStore:(NSURL *)storeURL withOptions:(NSDictionary *)options

Parameters

storeURL

the NSURL of the store to add

options

NSDictionary containing the options for the store

Return Value

BOOL YES if the add is successful, NO otherwise

Declared In

OCRCoreDataController.m

applicationDocumentsDirectory

Returns the URL to the application’s documents directory

- (NSURL *)applicationDocumentsDirectory

Return Value

NSURL of the application’s Documents Directory

Declared In

OCRCoreDataController.m

createStoreOptions

Helper method to configure the options for the NSPersistentStoreCoordinator object

- (NSDictionary *)createStoreOptions

Return Value

NSDictionry of the appropriate options

Declared In

OCRCoreDataController.m

managedObjectModel

Returns the managed object model for the application. If the model doesn’t already exist, it is created from the app’s model.

- (NSManagedObjectModel *)managedObjectModel

Discussion

I use Mogenerator to generate the concrete classes for the data model (KOResume.xcdatamodel). You can download Mogenerator from GitHub

The key thing with Mogenerator is you DO NOT WANT TO use Xcode’s built in model generator. I’ve create a build target (Mogenerator) to generate the model. If you prefer using terminal, navigate to the folder containing KOResume.xcodeproj and run the command:

    mogenerator -m Classes/DataModel/KOResume.xcdatamodeld/KOResume.xcdatamodel  -O Classes

Declared In

OCRCoreDataController.m

mergeChangesFrom_iCloud:

Invoked by NSNotification when iCloud has changes

- (void)mergeChangesFrom_iCloud:(NSNotification *)notification

Parameters

notification

the NSNotification object containing information about the changes

Declared In

OCRCoreDataController.m

merge_iCloudChanges:forContext:

Invoked when iCloud has changes to merge (currently, iCloud is disabled)

- (void)merge_iCloudChanges:(NSNotification *)aNote forContext:(NSManagedObjectContext *)moc

Parameters

aNote

the NSNotification object containing information about the changes

moc

the NSManagedObjectContext effected

Discussion

  • Invokes mergeChangesFromContextDidSaveNotification on the NSManagedObjectContext
  • Creates a NSNotification to inform interested parties that updates were merged

Declared In

OCRCoreDataController.m

persistentStoreCoordinator

Singleton object reference to the NSPersistentStoreCoordinator

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator

Declared In

OCRCoreDataController.m