Class

NSRelationshipDescription

A description of the relationships of an entity in an NSEntityDescription object.

Overview

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.

Topics

Managing Type Information

var destinationEntity: NSEntityDescription?

The entity description of the receiver's destination.

var inverseRelationship: NSRelationshipDescription?

The relationship that represents the inverse of the receiver.

Getting and Setting Delete Rules

var deleteRule: NSDeleteRule

The delete rule of the receiver.

Handling Cardinality

var maxCount: Int

The maximum count of the receiver.

var minCount: Int

The minimum count of the receiver.

var isToMany: Bool

A Boolean value that indicates whether the receiver represents a to-many relationship.

Controlling Ordering

var isOrdered: Bool

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

Supporting Versioning

var versionHash: Data

The version hash for the receiver.

Configuring Delete Rules

enum NSDeleteRule

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

Relationships

See Also

Inspecting Entities and Configurations

var entities: [NSEntityDescription]

The entities in the model.

var entitiesByName: [String : NSEntityDescription]

The entities of the model, keyed by name.

var configurations: [String]

All the available configuration names of the model.

func entities(forConfigurationName: String?)

Returns the entities of the model for a specified configuration.

func setEntities([NSEntityDescription], forConfigurationName: String)

Associates the specified entities with the model using the given configuration name.

class NSEntityDescription

A description of an entity in Core Data.

class NSAttributeDescription

A description of the attributes of an entity described by an instance of NSEntityDescription.

class NSManagedObjectID

A compact, universal identifier for a managed object.

class NSPropertyDescription

A description of the properties of an entity in a Core Data managed object model.