Inherits from NSObject
Declared in RKManagedObjectImporter.h

Overview

Instances of RKManagedObjectImporter perform bulk imports of managed objects into a persistent store from source files (typically in JSON or XML format) using object mappings. The importer provides functionality for updating an existing persistent store or creating a seed database that can be used to bootstrap a new persistent store with an initial data set.

The importer requires that the source files have a MIME type that is identifiable by file extension and be parsable using a parser registered with the shared parser registry.

Tasks

Other Methods

Initializing an Importer

Accessing Core Data Details

  •   persistentStore

    The persistent store in which imported managed objects will be persisted.

    property
  •   managedObjectModel

    The managed object model containing entities that may be imported by the receiver.

    property
  •   managedObjectContext

    A managed object context with the NSPrivateQueueConcurrencyType concurrency type used to perform the import.

    property
  •   storePath

    A convenience accessor for retrieving the complete filesystem path to the persistent store in which the receiver will persist imported managed objects.

    property
  •   managedObjectCache

    A class that conforms to the RKManagedObjectCaching protocol that should be used when performing the import.

    property

Importing Managed Objects

Obtaining Seeding Info

  • – logSeedingInfo

    Logs information about where on the filesystem to access the SQLite database for the persistent store in which the imported managed objects were persisted.

Properties

managedObjectCache

@property (nonatomic, strong) id<RKManagedObjectCaching> managedObjectCache
Discussion

A class that conforms to the RKManagedObjectCaching protocol that should be used when performing the import.

Default: An instance of RKInMemoryManagedObjectCache.

Declared In

RKManagedObjectImporter.h

managedObjectContext

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

A managed object context with the NSPrivateQueueConcurrencyType concurrency type used to perform the import.

Declared In

RKManagedObjectImporter.h

managedObjectModel

@property (nonatomic, strong, readonly) NSManagedObjectModel *managedObjectModel
Discussion

The managed object model containing entities that may be imported by the receiver.

Declared In

RKManagedObjectImporter.h

persistentStore

@property (nonatomic, strong, readonly) NSPersistentStore *persistentStore
Discussion

The persistent store in which imported managed objects will be persisted.

Declared In

RKManagedObjectImporter.h

resetsStoreBeforeImporting

@property (nonatomic, assign) BOOL resetsStoreBeforeImporting
Discussion

A Boolean value indicating whether existing managed objects in the persistent store should be deleted before import.

The default value of this property is YES if the receiver was initialized with a managed object model and store path, else NO.

Declared In

RKManagedObjectImporter.h

storePath

@property (nonatomic, strong, readonly) NSString *storePath
Discussion

A convenience accessor for retrieving the complete filesystem path to the persistent store in which the receiver will persist imported managed objects.

Equivalent to executing the following example code:

NSURL *URL = [importer.persistentStore.persistentStoreCoordinator URLForPersistentStore:importer.persistentStore];
return [URL path];

Declared In

RKManagedObjectImporter.h

Instance Methods

finishImporting:

- (BOOL)finishImporting:(NSError **)error
Discussion

Finishes the import process by saving the managed object context to the persistent store, ensuring all imported managed objects are written to disk.

Parameters

error

On input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.

Return Value

YES if the save to the persistent store was successful, else NO.

Declared In

RKManagedObjectImporter.h

importObjectsFromItemAtPath:withMapping:keyPath:error:

- (NSUInteger)importObjectsFromItemAtPath:(NSString *)path withMapping:(RKMapping *)mapping keyPath:(NSString *)keyPath error:(NSError **)error
Discussion

Imports managed objects from the file or directory at the given path.

Parameters

path

The path to the file or directory you wish to import. This parameter must not be nil.

mapping

The entity or dynamic mapping you wish to use for importing content at the given path.

keyPath

An optional key path to be evaluated against the results of parsing the content read at the given path. If the mappable content is not contained in a nesting attribute, the key path should be specified as nil.

error

On input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.

Return Value

A count of the number of managed object imported from the given path or NSNotFound if an error occurred during import.

Declared In

RKManagedObjectImporter.h

init

- (instancetype)init

initWithManagedObjectModel:storePath:

- (instancetype)initWithManagedObjectModel:(NSManagedObjectModel *)managedObjectModel storePath:(NSString *)storePath
Discussion

Initializes the receiver with a given managed object model and a path at which a SQLite persistent store should be created to persist imported managed objects.

When initialized with a managed object model and store path, the receiver will construct an internal persistent store coordinator, SQLite persistent store, and managed object context with the private queue concurrency type with which to perform the importing.

Warning: As this initialization code path is typical for generating seed databases, the value of resetsStoreBeforeImporting is initialized to YES.

Parameters

managedObjectModel

A Core Data manage object model with which to initialize the receiver.

storePath

The path at which to create a SQLite persistent store to persist the imported managed objects.

Return Value

The receiver, initialized with the given managed object model and a complete Core Data persistence stack with a SQLite persistent store at the given store path.

Declared In

RKManagedObjectImporter.h

initWithPersistentStore:

- (instancetype)initWithPersistentStore:(NSPersistentStore *)persistentStore
Discussion

Initializes the receiver with a given persistent store in which to persist imported managed objects.

When initialized with a persistent store, the receiver will construct a managed object context with the private queue concurrency type and the persistent store coordinator of the given persistent store. This prepares the receiver for importing content into an existing Core Data persistence stack.

Parameters

persistentStore

A Core Data persistent store with which to initialize the receiver.

Return Value

The receiver, initialized with the given persistent store. The persistent store coordinator and managed object model are determined from the given persistent store and a new managed object context with the private queue concurrency type is constructed.

Declared In

RKManagedObjectImporter.h

logSeedingInfo

- (void)logSeedingInfo
Discussion

Logs information about where on the filesystem to access the SQLite database for the persistent store in which the imported managed objects were persisted.

Declared In

RKManagedObjectImporter.h