NSAttributeDescription Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/CoreData.framework
Availability
Available in iOS 3.0 and later.
Declared in
NSAttributeDescription.h
Companion guides
Core Data Programming Guide
Core Data Utility Tutorial
Related sample code

Overview

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.

Tasks

Getting and Setting Type Information

Getting and Setting the Default Value

Versioning Support

Value Transformers

External Binary Storage

Instance Methods

allowsExternalBinaryDataStorage

Returns a Boolean value that indicates whether the attribute allows external binary storage.

- (BOOL)allowsExternalBinaryDataStorage
Return Value

YES if the attribute allows external binary storage, otherwise NO.

Discussion

If this value is YES, the corresponding attribute may be stored in a file external to the persistent store itself.

Availability
  • Available in iOS 5.0 and later.
Declared In
NSAttributeDescription.h

attributeType

Returns the type of the receiver.

- (NSAttributeType)attributeType
Return Value

The type of the receiver.

Availability
  • Available in iOS 3.0 and later.
Declared In
NSAttributeDescription.h

attributeValueClassName

Returns the name of the class used to represent the receiver.

- (NSString *)attributeValueClassName
Return Value

The name of the class used to represent the receiver, as a string.

Availability
  • Available in iOS 3.0 and later.
Related Sample Code
Declared In
NSAttributeDescription.h

defaultValue

Returns the default value of the receiver.

- (id)defaultValue
Return Value

The default value of the receiver.

Availability
  • Available in iOS 3.0 and later.
Declared In
NSAttributeDescription.h

setAllowsExternalBinaryDataStorage:

Sets whether the atribute allows

- (void)setAllowsExternalBinaryDataStorage:(BOOL)flag
Parameters
flag

A Boolean value that indicates whether the attribute should allow external binary storage.

Availability
  • Available in iOS 5.0 and later.
Declared In
NSAttributeDescription.h

setAttributeType:

Sets the type of the receiver.

- (void)setAttributeType:(NSAttributeType)type
Parameters
type

An NSAttributeType constant that specifies the type for the receiver.

Special Considerations

This method raises an exception if the receiver’s model has been used by an object graph manager.

Availability
  • Available in iOS 3.0 and later.
Related Sample Code
Declared In
NSAttributeDescription.h

setAttributeValueClassName:

Sets the name of the class used to represent the receiver.

- (void)setAttributeValueClassName:(NSString *)className
Parameters
className

The name of the class used to represent the receiver.

Discussion

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

Availability
  • Available in iOS 3.0 and later.
Declared In
NSAttributeDescription.h

setDefaultValue:

Sets the default value of the receiver.

- (void)setDefaultValue:(id)value
Parameters
value

The default value for the receiver.

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

This method raises an exception if the receiver’s model has been used by an object graph manager.

Availability
  • Available in iOS 3.0 and later.
Related Sample Code
Declared In
NSAttributeDescription.h

setValueTransformerName:

Sets the name of the transformer to use to transform the attribute value.

- (void)setValueTransformerName:(NSString *)string
Parameters
string

The name of the transformer to use to transform the attribute value. The transformer must output an NSData object from transformedValue: and must allow reverse transformations.

Discussion

The receiver must be an attribute of type NSTransformedAttributeType.

If this value is not set, or is set to nil, Core Data will default to using a transformer which uses NSCoding to archive and unarchive the attribute value.

Availability
  • Available in iOS 3.0 and later.
Declared In
NSAttributeDescription.h

valueTransformerName

Returns the name of the transformer used to transform the attribute value.

- (NSString *)valueTransformerName
Return Value

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

Discussion

The receiver must be an attribute of type NSTransformedAttributeType.

Availability
  • Available in iOS 3.0 and later.
Declared In
NSAttributeDescription.h

versionHash

Returns the version hash for the receiver.

- (NSData *)versionHash
Return Value

The version hash for the receiver.

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.

Availability
  • Available in iOS 3.0 and later.
See Also
Declared In
NSAttributeDescription.h

Constants

NSAttributeType

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

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

Declared in NSAttributeDescription.h.

NSInteger16AttributeType

Specifies a 16-bit signed integer attribute.

Available in iOS 3.0 and later.

Declared in NSAttributeDescription.h.

NSInteger32AttributeType

Specifies a 32-bit signed integer attribute.

Available in iOS 3.0 and later.

Declared in NSAttributeDescription.h.

NSInteger64AttributeType

Specifies a 64-bit signed integer attribute.

Available in iOS 3.0 and later.

Declared in NSAttributeDescription.h.

NSDecimalAttributeType

Specifies an NSDecimalNumber attribute.

Available in iOS 3.0 and later.

Declared in NSAttributeDescription.h.

NSDoubleAttributeType

Specifies a double attribute.

Available in iOS 3.0 and later.

Declared in NSAttributeDescription.h.

NSFloatAttributeType

Specifies a float attribute.

Available in iOS 3.0 and later.

Declared in NSAttributeDescription.h.

NSStringAttributeType

Specifies an NSString attribute.

Available in iOS 3.0 and later.

Declared in NSAttributeDescription.h.

NSBooleanAttributeType

Specifies a Boolean attribute.

Available in iOS 3.0 and later.

Declared in NSAttributeDescription.h.

NSDateAttributeType

Specifies an NSDate attribute.

Times are specified in GMT.

Available in iOS 3.0 and later.

Declared in NSAttributeDescription.h.

NSBinaryDataAttributeType

Specifies an NSData attribute.

Available in iOS 3.0 and later.

Declared in NSAttributeDescription.h.

NSTransformableAttributeType

Specifies an attribute that uses a value transformer.

Available in iOS 3.0 and later.

Declared in NSAttributeDescription.h.

NSObjectIDAttributeType

Specifies the object ID attribute.

Available in iOS 3.0 and later.

Declared in NSAttributeDescription.h.

Availability
  • Available in iOS 3.0 and later.
Declared In
NSAttributeDescription.h