Inherits from | |
Conforms to | |
Framework | /System/Library/Frameworks/CoreData.framework |
Availability | Available in Mac OS X v10.4 and later. |
Companion guide | |
Declared in | NSPropertyDescription.h |
Related sample code |
The NSPropertyDescription
class is used to define properties of an entity in a Core Data managed object model. Properties are to entities what instance variables are to classes.
A property describes a single value within an object managed by the Core Data Framework. There are different types of property, each represented by a subclass which encapsulates the specific property behavior—see NSAttributeDescription, NSRelationshipDescription, and NSFetchedPropertyDescription.
Note that a property name cannot be the same as any no-parameter method name of NSObject
or NSManagedObject
. For example, you cannot give a property the name "description". There are hundreds of methods on NSObject
which may conflict with property names—and this list can grow without warning from frameworks or other libraries. You should avoid very general words (like "font”, and “color”) and words or phrases which overlap with Cocoa paradigms (such as “isEditing” and “objectSpecifier”).
Properties—relationships as well as attributes—may be transient. A managed object context knows about transient properties and tracks changes made to them. Transient properties are ignored by the persistent store, and not just during saves: you cannot fetch using a predicate based on transients (although you can use transient properties to filter in memory yourself).
Property descriptions are editable until they are used by an object graph manager (such as a persistent store coordinator). 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.
Returns the entity description of the receiver.
- (NSEntityDescription *)entity
The entity description of the receiver.
setProperties:
(NSEntityDescription
)NSPropertyDescription.h
Returns a Boolean value that indicates whether the receiver is important for searching.
- (BOOL)isIndexed
YES
if the receiver is important for searching, otherwise NO
.
Object stores can optionally use this information upon store creation for operations such as defining indexes.
NSPropertyDescription.h
Returns a Boolean value that indicates whether the receiver is optional.
- (BOOL)isOptional
YES
if the receiver is optional, otherwise NO
.
NSPropertyDescription.h
Returns a Boolean value that indicates whether the receiver is transient.
- (BOOL)isTransient
YES
if the receiver is transient, otherwise NO
.
NSPropertyDescription.h
Returns the name of the receiver.
- (NSString *)name
The name of the receiver.
NSPropertyDescription.h
Sets the optionality flag of the receiver.
- (void)setIndexed:(BOOL)flag
A Boolean value that indicates whether whether the receiver is important for searching (YES
) or not (NO
).
Object stores can optionally use this information upon store creation for operations such as defining indexes.
This method raises an exception if the receiver’s model has been used by an object graph manager.
NSPropertyDescription.h
Sets the name of the receiver.
- (void)setName:(NSString *)name
The name of the receiver.
A property name cannot be the same as any no-parameter method name of NSObject
or NSManagedObject
. Since there are hundreds of methods on NSObject
which may conflict with property names, you should avoid very general words (like "font”, and “color”) and words or phrases which overlap with Cocoa paradigms (such as “isEditing” and “objectSpecifier”).
This method raises an exception if the receiver’s model has been used by an object graph manager.
NSPropertyDescription.h
Sets the optionality flag of the receiver.
- (void)setOptional:(BOOL)flag
A Boolean value that indicates whether whether the receiver is optional (YES
) or not (NO
).
The optionality flag specifies whether a property’s value can be nil
before an object can be saved to a persistent store.
This method raises an exception if the receiver’s model has been used by an object graph manager.
NSPropertyDescription.h
Sets the transient flag of the receiver.
- (void)setTransient:(BOOL)flag
A Boolean value that indicates whether whether the receiver is transient (YES
) or not (NO
).
The transient flag specifies whether or not a property’s value is ignored when an object is saved to a persistent store. Transient properties are not saved to the persistent store, but are still managed for undo, redo, validation, and so on.
This method raises an exception if the receiver’s model has been used by an object graph manager.
NSPropertyDescription.h
Sets the user info dictionary of the receiver.
- (void)setUserInfo:(NSDictionary *)dictionary
The user info dictionary of the receiver.
This method raises an exception if the receiver’s model has been used by an object graph manager.
NSPropertyDescription.h
Sets the validation predicates and warnings of the receiver.
- (void)setValidationPredicates:(NSArray *)validationPredicates withValidationWarnings:(NSArray *)validationWarnings
An array containing the validation predicates for the receiver.
An array containing the validation warnings for the receiver.
The validationPredicates and validationWarnings arrays should contain the same number of elements, and corresponding elements should appear at the same index in each array.
Instead of implementing individual validation methods, you can use this method to provide a list of predicates that are evaluated against the managed objects and a list of corresponding error messages (which can be localized).
This method raises an exception if the receiver’s model has been used by an object graph manager.
NSPropertyDescription.h
Sets the version hash modifier for the receiver.
- (void)setVersionHashModifier:(NSString *)modifierString
The version hash modifier for the receiver.
This value is included in the version hash for the property. You use it to mark or denote a property as being a different “version” than another even if all of the values which affect persistence are equal. (Such a difference is important in cases where the attributes of a property are unchanged but the format or content of its data are changed.)
NSPropertyDescription.h
Returns the user info dictionary of the receiver.
- (NSDictionary *)userInfo
The user info dictionary of the receiver.
NSPropertyDescription.h
Returns the validation predicates of the receiver.
- (NSArray *)validationPredicates
An array containing the receiver’s validation predicates.
NSPropertyDescription.h
Returns the error strings associated with the receiver’s validation predicates.
- (NSArray *)validationWarnings
An array containing the error strings associated with the receiver’s validation predicates.
NSPropertyDescription.h
Returns the version hash for the receiver.
- (NSData *)versionHash
The version hash for the receiver.
The version hash is used to uniquely identify a property based on its configuration. The version hash uses only values which affect the persistence of data and the user-defined versionHashModifier
value. (The values which affect persistence are the name of the property, and the flags for isOptional
, isTransient
, and isReadOnly
.) This value is stored as part of the version information in the metadata for stores, as well as a definition of a property involved in an NSPropertyMapping
object.
NSPropertyDescription.h
Returns the version hash modifier for the receiver.
- (NSString *)versionHashModifier
The version hash modifier for the receiver.
This value is included in the version hash for the property. See setVersionHashModifier:
for a full discussion.
NSPropertyDescription.h
© 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-10-03)