A description of a relationship of a Core Data entity.
SDKs
- iOS 3.0+
- macOS 10.4+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
Framework
- Core Data
Declaration
class NSRelationshipDescription : NSProperty Description
Overview
NSRelationship
extends NSProperty
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.