NSMappingModel 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
NSMappingModel.h

Overview

Instances of NSMappingModel specify how to map from a source to a destination managed object model.

Tasks

Creating a Mapping

Managing Entity Mappings

Class Methods

inferredMappingModelForSourceModel:destinationModel:error:

Returns a newly-created mapping model to migrate data from the source to the destination model.

+ (NSMappingModel *)inferredMappingModelForSourceModel:(NSManagedObjectModel *)source destinationModel:(NSManagedObjectModel *)destination error:(NSError **)error
Parameters
source

The source managed object model.

destination

The destination managed object model.

error

If a problem occurs, on return contains an NSInferredMappingModelError error that describes the problem.

The error’s user info will contain additional details about why inferring the mapping model failed (check for the following keys: reason, entity, property.

Return Value

A newly-created mapping model to migrate data from the source to the destination model. If the mapping model can not be created, returns nil.

Discussion

A model will be created only if all changes are simple enough to be able to reasonably infer a mapping (for example, removing or renaming an attribute, adding an optional attribute or relationship, or adding renaming or deleting an entity). Element IDs are used to track renamed properties and entities.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSMappingModel.h

mappingModelFromBundles:forSourceModel:destinationModel:

Returns the mapping model to translate data from the source to the destination model.

+ (NSMappingModel *)mappingModelFromBundles:(NSArray *)bundles forSourceModel:(NSManagedObjectModel *)sourceModel destinationModel:(NSManagedObjectModel *)destinationModel
Parameters
bundles

An array of bundles in which to search for mapping models.

sourceModel

The managed object model for the source store.

destinationModel

The managed object model for the destination store.

Return Value

Returns the mapping model to translate data from sourceModel to destinationModel. If a suitable mapping model cannot be found, returns nil.

Discussion

This method is a companion to the mergedModelFromBundles: and mergedModelFromBundles:forStoreMetadata: methods. In this case, the framework uses the version information from the models to locate the appropriate mapping model in the available bundles.

Availability
  • Available in OS X v10.5 and later.
Declared In
NSMappingModel.h

Instance Methods

entityMappings

Returns the collection of entity mappings for the receiver.

- (NSArray *)entityMappings
Return Value

The collection of entity mappings for the receiver.

Special Considerations

The order of the mappings in the array specifies the order in which they will be processed during migration.

Availability
  • Available in OS X v10.5 and later.
Declared In
NSMappingModel.h

entityMappingsByName

Returns a dictionary of the entity mappings for the receiver.

- (NSDictionary *)entityMappingsByName
Return Value

A dictionary of the entity mappings for the receiver, keyed by their respective name.

Discussion

You can use this method to quickly access to mapping by name, rather than iterating the ordered array returned by entityMappings.

Availability
  • Available in OS X v10.5 and later.
Declared In
NSMappingModel.h

initWithContentsOfURL:

Returns a mapping model initialized from a given URL.

- (id)initWithContentsOfURL:(NSURL *)url
Parameters
url

The location of an archived mapping model.

Return Value

A mapping model initialized from url.

Availability
  • Available in OS X v10.5 and later.
Declared In
NSMappingModel.h

setEntityMappings:

Sets the collection of entity mappings for the receiver

- (void)setEntityMappings:(NSArray *)mappings
Parameters
mappings

The collection of entity mappings for the receiver.

Special Considerations

The order of the mappings specifies the order in which they will be processed during migration.

Availability
  • Available in OS X v10.5 and later.
Declared In
NSMappingModel.h