Mac Developer Library

Developer

CoreData Framework Reference NSRelationshipDescription Class Reference

Options
Deployment Target:

On This Page
Language:

NSRelationshipDescription

Inheritance


Conforms To


Import Statement


Swift

import CoreData

Objective-C

@import CoreData;

Availability


Available in OS X v10.4 and later.

The NSRelationshipDescription class is used to describe relationships of an entity in an NSEntityDescription object.

NSRelationshipDescription extends NSPropertyDescription to describe features appropriate to relationships, including cardinality (the number of objects allowed in the relationship), the destination entity, and delete rules.

Cardinality

The maximum and minimum counts for a relationship indicate the number of objects referenced (1/1 for a to-one relationship, 0 means undefined). The counts are only enforced if the relationship value in the containing object is not nil. That is, optional relationships may have zero objects in the relationship, which might be less than the minimum count.

Editing Relationship Descriptions

Relationship descriptions are editable until they are used by an object graph manager. This allows you to create or modify them dynamically. However, once a description is used (when the managed object model to which it belongs is associated with a persistent store coordinator), it must not (indeed cannot) be changed. This is enforced at runtime: any attempt to mutate a model or any of its sub-objects after the model is associated with a persistent store coordinator causes an exception to be thrown. If you need to modify a model that is in use, create a copy, modify the copy, and then discard the objects with the old model.

  • The entity description of the receiver's destination.

    Declaration

    Swift

    unowned(unsafe) var destinationEntity: NSEntityDescription?

    Objective-C

    @property(nonatomic, assign) NSEntityDescription *destinationEntity

    Special Considerations

    Setting this property raises an exception if the receiver’s model has been used by an object graph manager.

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in OS X v10.4 and later.

  • The relationship that represents the inverse of the receiver.

    Declaration

    Swift

    unowned(unsafe) var inverseRelationship: NSRelationshipDescription?

    Objective-C

    @property(nonatomic, assign) NSRelationshipDescription *inverseRelationship

    Discussion

    Given a to-many relationship “employees” between a Department entity and an Employee entity (a department may have many employees), and a to-one relationship “department” between an Employee entity and a Department entity (an employee may belong to only one department), the inverse of the “department” relationship is the “employees” relationship.

    Special Considerations

    Setting this property raises an exception if the receiver’s model has been used by an object graph manager.

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in OS X v10.4 and later.

  • The delete rule of the receiver.

    Declaration

    Swift

    var deleteRule: NSDeleteRule

    Objective-C

    @property NSDeleteRule deleteRule

    Special Considerations

    Setting this property raises an exception if the receiver’s model has been used by an object graph manager.

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in OS X v10.4 and later.

  • maxCount maxCount Property

    The maximum count of the receiver.

    Declaration

    Swift

    var maxCount: Int

    Objective-C

    @property NSUInteger maxCount

    Special Considerations

    Setting this property raises an exception if the receiver’s model has been used by an object graph manager.

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in OS X v10.4 and later.

  • minCount minCount Property

    The minimum count of the receiver.

    Declaration

    Swift

    var minCount: Int

    Objective-C

    @property NSUInteger minCount

    Special Considerations

    Setting this property raises an exception if the receiver’s model has been used by an object graph manager.

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in OS X v10.4 and later.

    See Also

    – maxCount

  • toMany toMany Property

    A Boolean value that indicates whether the receiver represents a to-many relationship. (read-only)

    Declaration

    Swift

    var toMany: Bool { get }

    Objective-C

    @property(getter=isToMany, readonly) BOOL toMany

    Discussion

    YEStrue if the receiver represents a to-many relationship (its maxCount is greater than 1) otherwise NOfalse.

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in OS X v10.10 and later.

    See Also

    – maxCount

  • ordered ordered Property

    Returns a Boolean value that indicates whether the receiver describes an ordered relationship.

    Declaration

    Swift

    var ordered: Bool

    Objective-C

    @property(getter=isOrdered) BOOL ordered

    Discussion

    YEStrue if the relationship is ordered, otherwise NOfalse.

    Special Considerations

    Setting this property raises an exception if the receiver’s model has been used by an object graph manager.

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in OS X v10.7 and later.

  • The version hash for the receiver. (read-only)

    Declaration

    Swift

    @NSCopying var versionHash: NSData { get }

    Objective-C

    @property(readonly, copy) NSData *versionHash

    Discussion

    The version hash is used to uniquely identify an attribute based on its configuration. This value includes the versionHash information from NSPropertyDescription, the name of the destination entity and the inverse relationship, and the min and max count.

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in OS X v10.5 and later.

    See Also

    versionHash (NSPropertyDescription)

Data Types

  • These constants define what happens to relationships when an object is deleted.

    Declaration

    Swift

    enum NSDeleteRule : UInt { case NoActionDeleteRule case NullifyDeleteRule case CascadeDeleteRule case DenyDeleteRule }

    Objective-C

    typedef enum { NSNoActionDeleteRule, NSNullifyDeleteRule, NSCascadeDeleteRule, NSDenyDeleteRule } NSDeleteRule;

    Constants

    • NoActionDeleteRule

      NSNoActionDeleteRule

      If the object is deleted, no modifications are made to objects at the destination of the relationship.

      If you use this rule, you are responsible for maintaining the integrity of the object graph. This rule is strongly discouraged for all but advanced users. You should normally use NSNullifyDeleteRule instead.

      Available in OS X v10.4 and later.

    • NullifyDeleteRule

      NSNullifyDeleteRule

      If the object is deleted, back pointers from the objects to which it is related are nullified.

      Available in OS X v10.4 and later.

    • CascadeDeleteRule

      NSCascadeDeleteRule

      If the object is deleted, the destination object or objects of this relationship are also deleted.

      Available in OS X v10.4 and later.

    • DenyDeleteRule

      NSDenyDeleteRule

      If the destination of this relationship is not nil, the delete creates a validation error.

      Available in OS X v10.4 and later.

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in OS X v10.4 and later.