Inherits from NSObject
Declared in RKEntityIdentifier.h

Overview

The RKEntityIdentifier object describes a means for uniquely identifying one or more NSManagedObject objects within a Core Data managed object model. Entity identifiers are used by RestKit to identify existing managed objects that are to be updated while performing object mapping with an RKEntityMapping object. Entity identifiers identify objects by specifying the attributes that can be used to uniquely differentiate managed objects within a context.

Tasks

Initializing an Entity Identifier

Accessing Entity Identity

  •   entity

    The entity that the receiver identifies.

    property
  •   attributes

    An array of NSAttributeDescription objects specifying the attributes used for identification.

    property

Filtering the Identified Objects

  •   predicate

    An optional predicate for filtering identified objects.

    property

Inferring Identifiers from the Model

Properties

attributes

An array of NSAttributeDescription objects specifying the attributes used for identification.

@property (nonatomic, copy, readonly) NSArray *attributes

Declared In

RKEntityIdentifier.h

entity

The entity that the receiver identifies.

@property (nonatomic, strong, readonly) NSEntityDescription *entity

Declared In

RKEntityIdentifier.h

predicate

An optional predicate for filtering identified objects.

@property (nonatomic, copy) NSPredicate *predicate

Declared In

RKEntityIdentifier.h

Class Methods

identifierWithEntityName:attributes:inManagedObjectStore:

Creates and returns a new entity identifier with the entity for the given name and attributes in the specified managed object store.

+ (id)identifierWithEntityName:(NSString *)entityName attributes:(NSArray *)attributes inManagedObjectStore:(RKManagedObjectStore *)managedObjectStore

Parameters

entityName

The name of the entity being identified.

attributes

An array of NSString objects containing the names of attributes or NSAttributeDescription objects specifying the identifying attributes for the entity.

managedObjectStore

The managed object store containing the managed object model within which the entity exists.

Return Value

A new entity identifier, configured with the given entity for the given name and the array of attributes.

Declared In

RKEntityIdentifier.h

inferredIdentifierForEntity:

Creates and returns an entity identifier for the given entity inferred from the managed object model.

+ (RKEntityIdentifier *)inferredIdentifierForEntity:(NSEntityDescription *)entity

Parameters

entity

The entity to infer an identifier for.

Return Value

An entity identifier inferred from the model for the given entity, or nil if none could be inferred.

Discussion

When inferring an entity identifier, the entity is first checked for a user info key specifying the identifying attributes. If the user info of the given entity contains a value for the key ‘RKEntityIdentifierAttributes’, then that value is used to construct an entity identifier. The user info key must contain a string or an array of strings specifying the names of attributes that exist in the given entity.

If no attributes are specified in the user info, then the entity is searched for an attribute whose name matches the llama-cased name of the entity. For example, an entity named ‘Article’ would have an inferred identifier attribute of ‘articleID’ and an entity named ‘ApprovedComment’ would be inferred as ‘approvedCommentID’. If such an attribute is found within the entity, an identifier is returned specifying that attribute. If none is returned, the the attributes are search for the following names:

  1. ‘identifier’
  2. ‘ID’
  3. ‘URL’
  4. ‘url’

If any of these attributes are found, then an entity identifier is created for that attribute. If all possible inferred attributes are exhausted, then nil is returned.

Declared In

RKEntityIdentifier.h

Instance Methods

initWithEntity:attributes:

Initializes the receiver with a given entity and array of attributes.

- (id)initWithEntity:(NSEntityDescription *)entity attributes:(NSArray *)attributes

Parameters

entity

The entity being identified.

attributes

An array of NSString objects containing the names of attributes or NSAttributeDescription objects specifying the identifying attributes for the entity.

Return Value

The receiver, initialized with the given entity and attributes.

Declared In

RKEntityIdentifier.h