Mac Developer Library

Developer

CoreData Framework Reference NSEntityMapping Class Reference

Options
Deployment Target:

On This Page
Language:

NSEntityMapping

Instances of NSEntityMapping specify how to map an entity from a source to a destination managed object model.

Inheritance


Conforms To


Import Statement


Swift

import CoreData

Objective-C

@import CoreData;

Availability


Available in OS X v10.5 and later.
  • The source entity name for the receiver.

    Declaration

    Swift

    var sourceEntityName: String

    Objective-C

    @property(copy) NSString *sourceEntityName

    Discussion

    Mappings are not directly bound to entity descriptions; you can use the sourceEntityForEntityMapping: method on the migration manager to retrieve the entity description for this entity name.

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in OS X v10.5 and later.

  • The version hash for the source entity for the receiver.

    Declaration

    Swift

    @NSCopying var sourceEntityVersionHash: NSData

    Objective-C

    @property(copy) NSData *sourceEntityVersionHash

    Discussion

    The version hash is calculated by Core Data based on the property values of the entity (see NSEntityDescription’s versionHash method). The sourceEntityVersionHash must equal the version hash of the source entity represented by the mapping.

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in OS X v10.5 and later.

  • The source expression for the receiver.

    Declaration

    Swift

    var sourceExpression: NSExpression?

    Objective-C

    @property(strong) NSExpression *sourceExpression

    Discussion

    The source expression is used to obtain the collection of managed objects to process through the mapping. The expression can be a fetch request expression, or any other expression that evaluates to a collection.

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in OS X v10.5 and later.

  • The destination entity name for the receiver.

    Declaration

    Swift

    var destinationEntityName: String?

    Objective-C

    @property(copy) NSString *destinationEntityName

    Discussion

    Mappings are not directly bound to entity descriptions. You can use the migration manager’s destinationEntityForEntityMapping: method to retrieve the entity description for this entity name.

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in OS X v10.5 and later.

  • The version hash for the destination entity for the receiver.

    Declaration

    Swift

    @NSCopying var destinationEntityVersionHash: NSData?

    Objective-C

    @property(copy) NSData *destinationEntityVersionHash

    Discussion

    The version hash is calculated by Core Data based on the property values of the entity (see NSEntityDescription’s versionHash method). The destinationEntityVersionHash must equal the version hash of the destination entity represented by the mapping.

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in OS X v10.5 and later.

  • name name Property

    The name of the receiver.

    Declaration

    Swift

    var name: String!

    Objective-C

    @property(copy) NSString *name

    Discussion

    The name is used only as a means of distinguishing mappings in a model. If not specified, the value defaults to SOURCE->DESTINATION.

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in OS X v10.5 and later.

  • The mapping type for the receiver.

    Declaration

    Swift

    var mappingType: NSEntityMappingType

    Objective-C

    @property NSEntityMappingType mappingType

    Discussion

    If you specify a custom entity mapping type, you must specify a value for the migration policy class name as well (see entityMigrationPolicyClassName).

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in OS X v10.5 and later.

  • The class name of the migration policy for the receiver.

    Declaration

    Swift

    var entityMigrationPolicyClassName: String

    Objective-C

    @property(copy) NSString *entityMigrationPolicyClassName

    Discussion

    If not specified, the default migration class name is NSEntityMigrationPolicy. You can specify a subclass to provide custom behavior.

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in OS X v10.5 and later.

  • The array of attribute mappings for the receiver.

    Declaration

    Swift

    var attributeMappings: [AnyObject]?

    Objective-C

    @property(strong) NSArray *attributeMappings

    Special Considerations

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

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in OS X v10.5 and later.

  • The array of relationship mappings for the receiver.

    Declaration

    Swift

    var relationshipMappings: [AnyObject]

    Objective-C

    @property(strong) NSArray *relationshipMappings

    Special Considerations

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

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in OS X v10.5 and later.

  • userInfo userInfo Property

    The user info dictionary for the receiver.

    Declaration

    Swift

    var userInfo: [NSObject : AnyObject]?

    Objective-C

    @property(nonatomic, strong) NSDictionary *userInfo

    Discussion

    You can use the info dictionary in any way that might be useful in your migration. You can set the contents of the dictionary directory or using the appropriate inspector in the Xcode mapping model editor.

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in OS X v10.5 and later.

Data Types

  • Data type used for constants that specify types of entity mapping.

    Declaration

    Swift

    enum NSEntityMappingType : UInt { case UndefinedEntityMappingType case CustomEntityMappingType case AddEntityMappingType case RemoveEntityMappingType case CopyEntityMappingType case TransformEntityMappingType }

    Objective-C

    typedef NSUInteger NSEntityMappingType;

    Discussion

    For possible values, see Entity Mapping Types.

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in OS X v10.5 and later.

  • These constants specify the types of entity mapping.

    Declaration

    Swift

    enum NSEntityMappingType : UInt { case UndefinedEntityMappingType case CustomEntityMappingType case AddEntityMappingType case RemoveEntityMappingType case CopyEntityMappingType case TransformEntityMappingType }

    Objective-C

    enum { NSUndefinedEntityMappingType = 0x00, NSCustomEntityMappingType = 0x01, NSAddEntityMappingType = 0x02, NSRemoveEntityMappingType = 0x03, NSCopyEntityMappingType = 0x04, NSTransformEntityMappingType = 0x05 };

    Constants

    • UndefinedEntityMappingType

      NSUndefinedEntityMappingType

      Specifies that the developer handles destination instance creation.

      Available in OS X v10.5 and later.

    • CustomEntityMappingType

      NSCustomEntityMappingType

      Specifies a custom mapping.

      Available in OS X v10.5 and later.

    • AddEntityMappingType

      NSAddEntityMappingType

      Specifies that this is a new entity in the destination model.

      Instances of the entity only exist in the destination.

      Available in OS X v10.5 and later.

    • RemoveEntityMappingType

      NSRemoveEntityMappingType

      Specifies that this entity is not present in the destination model.

      Instances of the entity only exist in the source—source instances are not mapped to destination.

      Available in OS X v10.5 and later.

    • CopyEntityMappingType

      NSCopyEntityMappingType

      Specifies that source instances are migrated as-is.

      Available in OS X v10.5 and later.

    • TransformEntityMappingType

      NSTransformEntityMappingType

      Specifies that entity exists in source and destination and is mapped.

      Available in OS X v10.5 and later.