iOS Developer Library

Developer

CoreData Framework Reference NSAttributeDescription Class Reference

Options
Deployment Target:

On This Page
Language:

NSAttributeDescription

Inheritance


Conforms To


Import Statement


Swift

import CoreData

Objective-C

@import CoreData;

Availability


Available in iOS 3.0 and later.

The NSAttributeDescription class is used to describe attributes of an entity described by an instance of NSEntityDescription.

NSAttributeDescription inherits from NSPropertyDescription, which provides most of the basic behavior. Instances of NSAttributeDescription 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 (NSUndefinedAttributeType) 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.

  • The type of the attribute.

    Declaration

    Swift

    var attributeType: NSAttributeType

    Objective-C

    @property NSAttributeType attributeType

    Discussion

    Setting the attribute type raises an exception if the model the attribute belongs to has been used by an object graph manager.

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in iOS 3.0 and later.

  • The name of the class used to represent the attribute.

    Declaration

    Swift

    var attributeValueClassName: String?

    Objective-C

    @property(copy) NSString *attributeValueClassName

    Discussion

    If you set the value class name, Core Data can check the class of any instance set as the value of an attribute.

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in iOS 3.0 and later.

  • The default value of the attribute.

    Declaration

    Swift

    var defaultValue: AnyObject?

    Objective-C

    @property(retain) id defaultValue

    Discussion

    Default values 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.

    Special Considerations

    Setting the default value 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 iOS 3.0 and later.

  • The version hash for the attribute. (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 and the attribute type.

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in iOS 3.0 and later.

    See Also

    versionHash (NSPropertyDescription)

  • The name of the transformer used to transform the attribute value.

    Declaration

    Swift

    var valueTransformerName: String?

    Objective-C

    @property(copy) NSString *valueTransformerName

    Discussion

    The attribute must be of type NSTransformedAttributeType.

    The transformer must output an NSData object from transformedValue: and must allow reverse transformations.

    If this value is nil, Core Data uses a default a transformer that uses NSCoding to archive and unarchive the attribute value.

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in iOS 3.0 and later.

  • A Boolean value that indicates whether the attribute allows external binary storage.

    Declaration

    Swift

    var allowsExternalBinaryDataStorage: Bool

    Objective-C

    @property BOOL allowsExternalBinaryDataStorage

    Discussion

    YEStrue if the attribute allows external binary storage, otherwise NOfalse. If this value is YEStrue, the corresponding attribute may be stored in a file external to the persistent store itself.

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in iOS 5.0 and later.

Data Types

  • Defines the possible types of NSAttributeType properties. These explicitly distinguish between bit sizes to ensure data store independence.

    Declaration

    Swift

    enum NSAttributeType : UInt { case UndefinedAttributeType case Integer16AttributeType case Integer32AttributeType case Integer64AttributeType case DecimalAttributeType case DoubleAttributeType case FloatAttributeType case StringAttributeType case BooleanAttributeType case DateAttributeType case BinaryDataAttributeType case TransformableAttributeType case ObjectIDAttributeType }

    Objective-C

    typedef enum { NSUndefinedAttributeType = 0, NSInteger16AttributeType = 100, NSInteger32AttributeType = 200, NSInteger64AttributeType = 300, NSDecimalAttributeType = 400, NSDoubleAttributeType = 500, NSFloatAttributeType = 600, NSStringAttributeType = 700, NSBooleanAttributeType = 800, NSDateAttributeType = 900, NSBinaryDataAttributeType = 1000, NSTransformableAttributeType = 1800, NSObjectIDAttributeType = 2000 } NSAttributeType;

    Constants

    • UndefinedAttributeType

      NSUndefinedAttributeType

      Specifies an undefined attribute type.

      NSUndefinedAttributeType is valid for transient properties—Core Data will still track the property as an id value and register undo/redo actions, and so on. NSUndefinedAttributeType is illegal for non-transient properties.

      Available in iOS 3.0 and later.

    • Integer16AttributeType

      NSInteger16AttributeType

      Specifies a 16-bit signed integer attribute.

      Available in iOS 3.0 and later.

    • Integer32AttributeType

      NSInteger32AttributeType

      Specifies a 32-bit signed integer attribute.

      Available in iOS 3.0 and later.

    • Integer64AttributeType

      NSInteger64AttributeType

      Specifies a 64-bit signed integer attribute.

      Available in iOS 3.0 and later.

    • DecimalAttributeType

      NSDecimalAttributeType

      Specifies an NSDecimalNumber attribute.

      Available in iOS 3.0 and later.

    • DoubleAttributeType

      NSDoubleAttributeType

      Specifies a double attribute.

      Available in iOS 3.0 and later.

    • FloatAttributeType

      NSFloatAttributeType

      Specifies a float attribute.

      Available in iOS 3.0 and later.

    • StringAttributeType

      NSStringAttributeType

      Specifies an NSString attribute.

      Available in iOS 3.0 and later.

    • BooleanAttributeType

      NSBooleanAttributeType

      Specifies a Boolean attribute.

      Available in iOS 3.0 and later.

    • DateAttributeType

      NSDateAttributeType

      Specifies an NSDate attribute.

      Times are specified in GMT.

      Available in iOS 3.0 and later.

    • BinaryDataAttributeType

      NSBinaryDataAttributeType

      Specifies an NSData attribute.

      Available in iOS 3.0 and later.

    • TransformableAttributeType

      NSTransformableAttributeType

      Specifies an attribute that uses a value transformer.

      Available in iOS 3.0 and later.

    • ObjectIDAttributeType

      NSObjectIDAttributeType

      Specifies the object ID attribute.

      Available in iOS 3.0 and later.

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in iOS 3.0 and later.