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

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

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

managedObjectContext

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

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

Declared In

RKManagedObjectImporter.h

managedObjectModel

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

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

Declared In

RKManagedObjectImporter.h

persistentStore

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

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

Declared In

RKManagedObjectImporter.h

resetsStoreBeforeImporting

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

@property (nonatomic, assign) BOOL resetsStoreBeforeImporting

Discussion

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

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

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

Discussion

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:

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

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

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:

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

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

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

initWithManagedObjectModel:storePath:

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.

- (id)initWithManagedObjectModel:(NSManagedObjectModel *)managedObjectModel storePath:(NSString *)storePath

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.

Discussion

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**.

Declared In

RKManagedObjectImporter.h

initWithPersistentStore:

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

- (id)initWithPersistentStore:(NSPersistentStore *)persistentStore

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.

Discussion

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.

Declared In

RKManagedObjectImporter.h

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.

- (void)logSeedingInfo

Declared In

RKManagedObjectImporter.h