NSMigrationManager Class Reference
| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/CoreData.framework |
| Availability | Available in OS X v10.5 and later. |
| Companion guide | |
| Declared in | NSMigrationManager.h |
Overview
Instances of NSMigrationManager perform a migration of data from one persistent store to another using a given mapping model.
Tasks
Initializing a Manager
Performing Migration Operations
-
– migrateStoreFromURL:type:options:withMappingModel:toDestinationURL:destinationType:destinationOptions:error: -
– reset -
– cancelMigrationWithError:
Monitoring Migration Progress
Working with Source and Destination Instances
-
– associateSourceInstance:withDestinationInstance:forEntityMapping: -
– destinationInstancesForEntityMappingNamed:sourceInstances: -
– sourceInstancesForEntityMappingNamed:destinationInstances:
Getting Information About a Migration Manager
-
– mappingModel -
– sourceModel -
– destinationModel -
– sourceEntityForEntityMapping: -
– destinationEntityForEntityMapping: -
– sourceContext -
– destinationContext -
– userInfo
Using Store-Specific Migration Managers
Instance Methods
associateSourceInstance:withDestinationInstance:forEntityMapping:
Associates a given source instance with an array of destination instances for a given property mapping.
Parameters
- sourceInstance
A source managed object.
- destinationInstance
The destination manage object for sourceInstance.
- entityMapping
The entity mapping to use to associate sourceInstance with the object in destinationInstances.
Discussion
Data migration is performed as a three-stage process (first create the data, then relate the data, then validate the data). You use this method to associate data between the source and destination stores, in order to allow for relationship creation or fix-up after the creation stage.
This method is called in the default implementation of NSEntityMigrationPolicy’s createDestinationInstancesForSourceInstance:entityMapping:manager:error: method.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSMigrationManager.hcancelMigrationWithError:
Cancels the migration with a given error.
Parameters
- error
An error object that describes the reason why the migration is canceled.
Discussion
You can invoke this method from anywhere in the migration process to abort the migration. Calling this method causes migrateStoreFromURL:type:options:withMappingModel:toDestinationURL:destinationType:destinationOptions:error: to abort the migration and return error—you should provide an appropriate error to indicate the reason for the cancellation.
Availability
- Available in OS X v10.5 and later.
Declared In
NSMigrationManager.hcurrentEntityMapping
Returns the entity mapping currently being processed.
Return Value
The entity mapping currently being processed.
Discussion
Each entity is processed a total of three times (instance creation, relationship creation, validation).
Special Considerations
You can observe this value using key-value observing.
Availability
- Available in OS X v10.5 and later.
Declared In
NSMigrationManager.hdestinationContext
Returns the managed object context the receiver uses for writing the destination persistent store.
Return Value
The managed object context the receiver uses for writing the destination persistent store.
Discussion
This context is created on demand as part of the initialization of the Core Data stacks used for migration.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSMigrationManager.hdestinationEntityForEntityMapping:
Returns the entity description for the destination entity of a given entity mapping.
Parameters
- mEntity
An entity mapping.
Return Value
The entity description for the destination entity of mEntity.
Discussion
Entity mappings do not store the actual description objects, but rather the name and version information of the entity.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSMigrationManager.hdestinationInstancesForEntityMappingNamed:sourceInstances:
Returns the managed object instances created in the destination store for a named entity mapping for a given array of source instances.
Parameters
- mappingName
The name of an entity mapping in use.
- sourceInstances
A array of managed objects in the source store.
Return Value
An array containing the managed object instances created in the destination store for the entity mapping named mappingName for sourceInstances. If sourceInstances is nil, all of the destination instances created by the specified property mapping are returned.
Special Considerations
This method throws an NSInvalidArgumentException exception if mappingName is not a valid mapping name.
Availability
- Available in OS X v10.5 and later.
Declared In
NSMigrationManager.hdestinationModel
Returns the destination model for the receiver.
Return Value
The destination model for the receiver.
Availability
- Available in OS X v10.5 and later.
Declared In
NSMigrationManager.hinitWithSourceModel:destinationModel:
Initializes a migration manager instance with given source and destination models.
Parameters
- sourceModel
The source managed object model for the migration manager.
- destinationModel
The destination managed object model for the migration manager.
Return Value
A migration manager instance initialized to migrate data in a store that uses sourceModel to a store that uses destinationModel.
Discussion
You specify the mapping model in the migration method, migrateStoreFromURL:type:options:withMappingModel:toDestinationURL:destinationType:destinationOptions:error:.
Special Considerations
This is the designated initializer for NSMigrationManager.
Although validation of the models is performed during migrateStoreFromURL:type:options:withMappingModel:toDestinationURL:destinationType:destinationOptions:error:, as with NSPersistentStoreCoordinator once models are added to the migration manager they are immutable and cannot be altered.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSMigrationManager.hmappingModel
Returns the mapping model for the receiver.
Return Value
The mapping model for the receiver.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSMigrationManager.hmigrateStoreFromURL:type:options:withMappingModel:toDestinationURL:destinationType:destinationOptions:error:
Migrates of the store at a given source URL to the store at a given destination URL, performing all of the mappings specified in a given mapping model.
Parameters
- sourceURL
The location of an existing persistent store. A store must exist at this URL.
- sStoreType
The type of store at sourceURL (see
NSPersistentStoreCoordinatorfor possible values).- sOptions
A dictionary of options for the source (see
NSPersistentStoreCoordinatorfor possible values).- mappings
The mapping model to use to effect the migration.
- dURL
The location of the destination store.
- dStoreType
The type of store at dURL (see
NSPersistentStoreCoordinatorfor possible values).- dOptions
A dictionary of options for the destination (see
NSPersistentStoreCoordinatorfor possible values).- error
If an error occurs during the validation or migration, upon return contains an
NSErrorobject that describes the problem.
Return Value
YES if the migration proceeds without errors during the compatibility checks or migration, otherwise NO.
Discussion
This method performs compatibility checks on the source and destination models and the mapping model.
Special Considerations
If a store does not exist at the destination URL (dURL), one is created; otherwise, the migration appends to the existing store.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSMigrationManager.hmigrationProgress
Returns a number from 0 to 1 that indicates the proportion of completeness of the migration.
Return Value
A number from 0 to 1 that indicates the proportion of completeness of the migration. If a migration is not taking place, returns 1.
Special Considerations
You can observe this value using key-value observing.
Availability
- Available in OS X v10.5 and later.
Declared In
NSMigrationManager.hreset
Resets the association tables for the migration.
Special Considerations
This method does not reset the source or destination contexts.
Availability
- Available in OS X v10.5 and later.
Declared In
NSMigrationManager.hsetUserInfo:
Sets the user info for the receiver.
Parameters
- dict
The user info for the receiver.
Discussion
You can use the user info dictionary to aid the customization of your migration process.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSMigrationManager.hsetUsesStoreSpecificMigrationManager:
Sets whether the receiver tries to use a store specific migration manager to perform the migration.
Parameters
- flag
YESto use a store-specific migration manager, otherwiseNO.
Discussion
A store-specific migration manager class is not guaranteed to perform any of the migration manager delegate callbacks or update values for the observable properties.
The default value is YES.
Availability
- Available in OS X v10.7 and later.
See Also
Declared In
NSMigrationManager.hsourceContext
Returns the managed object context the receiver uses for reading the source persistent store.
Return Value
The managed object context the receiver uses for reading the source persistent store.
Discussion
This context is created on demand as part of the initialization of the Core Data stacks used for migration.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSMigrationManager.hsourceEntityForEntityMapping:
Returns the entity description for the source entity of a given entity mapping.
Parameters
- mEntity
An entity mapping.
Return Value
The entity description for the source entity of mEntity.
Discussion
Entity mappings do not store the actual description objects, but rather the name and version information of the entity.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSMigrationManager.hsourceInstancesForEntityMappingNamed:destinationInstances:
Returns the managed object instances in the source store used to create a given destination instance for a given property mapping.
Parameters
- mappingName
The name of an entity mapping in use.
- destinationInstances
A array of managed objects in the destination store.
Return Value
An array containing the managed object instances in the source store used to create destinationInstances using the entity mapping named mappingName. If destinationInstances is nil, all of the source instances used to create the destination instance for this property mapping are returned.
Special Considerations
This method throws an NSInvalidArgumentException exception if mappingName is not a valid mapping name.
Availability
- Available in OS X v10.5 and later.
Declared In
NSMigrationManager.hsourceModel
Returns the source model for the receiver.
Return Value
The source model for the receiver.
Availability
- Available in OS X v10.5 and later.
Declared In
NSMigrationManager.huserInfo
Returns the user info for the receiver.
Return Value
The user info for the receiver.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSMigrationManager.husesStoreSpecificMigrationManager
Returns a Boolean value that indicates whether the receiver tries to use a store specific migration manager to perform the migration.
Return Value
YES if the receiver uses a store-specific migration manager, otherwise NO.
Discussion
For more discussion, see setUsesStoreSpecificMigrationManager:.
Availability
- Available in OS X v10.7 and later.
Declared In
NSMigrationManager.h© 2011 Apple Inc. All Rights Reserved. (Last updated: 2011-10-12)