Mac Developer Library

Developer

CoreData Framework Reference NSMappingModel Class Reference

Options
Deployment Target:

On This Page
Language:

NSMappingModel

Inheritance


Conforms To


Import Statement


Swift

import CoreData

Objective-C

@import CoreData;

Availability


Available in OS X v10.5 and later.

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

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

    Declaration

    Swift

    init?(fromBundles bundles: [AnyObject]?, forSourceModel sourceModel: NSManagedObjectModel?, destinationModel destinationModel: NSManagedObjectModel?) -> NSMappingModel

    Objective-C

    + (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.

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in OS X v10.5 and later.

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

    Declaration

    Swift

    class func inferredMappingModelForSourceModel(_ source: NSManagedObjectModel, destinationModel destination: NSManagedObjectModel, error error: NSErrorPointer) -> NSMappingModel?

    Objective-C

    + (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.

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in OS X v10.6 and later.

  • Returns a mapping model initialized from a given URL.

    Declaration

    Swift

    init?(contentsOfURL url: NSURL?)

    Objective-C

    - (instancetype)initWithContentsOfURL:(NSURL *)url

    Parameters

    url

    The location of an archived mapping model.

    Return Value

    A mapping model initialized from url.

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in OS X v10.5 and later.

  • The entity mappings for the receiver.

    Declaration

    Swift

    var entityMappings: [AnyObject]?

    Objective-C

    @property(strong) NSArray *entityMappings

    Special Considerations

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

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in OS X v10.5 and later.

  • The entity mappings for the receiver, keyed by name. (read-only)

    Declaration

    Swift

    var entityMappingsByName: [NSObject : AnyObject] { get }

    Objective-C

    @property(readonly, copy) NSDictionary *entityMappingsByName

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in OS X v10.5 and later.

    See Also

    entityMappings