A description of an attribute 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
@interface NSAttributeDescription : NSProperty Description
Overview
NSAttribute
inherits from NSProperty
, which provides most of the basic behavior. Instances of NSAttribute
are used to describe attributes, as distinct from relationships. The class adds the ability to specify the attribute type, and to specify a default value. In a managed object model, you must specify the type of all attributes—you can only use the undefined attribute type (NSUndefined
) for transient attributes.
Editing Attribute Descriptions
Attribute 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.
Note
Default values set for attributes are retained by a managed object model, not copied. This means that attribute values do not have to implement the NSCopying
protocol, however it also means that you should not modify any objects after they have been set as default values.