iOS Developer Library

Developer

CoreData Framework Reference NSManagedObjectID Class Reference

Options
Deployment Target:

On This Page
Language:

NSManagedObjectID

An NSManagedObjectID object is a compact, universal identifier for a managed object. This forms the basis for uniquing in the Core Data Framework. A managed object ID uniquely identifies the same managed object both between managed object contexts in a single application, and in multiple applications (as in distributed systems). Identifiers contain the information needed to exactly describe an object in a persistent store (like the primary key in the database), although the detailed information is not exposed. The framework completely encapsulates the “external” information and presents a clean object oriented interface.

Object IDs can be transformed into a URI representation which can be archived and recreated later to refer back to a given object (using managedObjectIDForURIRepresentation: (NSPersistentStoreCoordinator) and objectWithID: (NSManagedObjectContext). For example, the last selected group in an application could be stored in the user defaults through the group object’s ID. You can also use object ID URI representations to store “weak” relationships across persistent stores (where no hard join is possible).

Inheritance


Conforms To


Import Statement


Swift

import CoreData

Objective-C

@import CoreData;

Availability


Available in iOS 3.0 and later.
  • entity entity Property

    The entity description associated with the object ID. (read-only)

    Declaration

    Swift

    var entity: NSEntityDescription { get }

    Objective-C

    @property(readonly, strong) NSEntityDescription *entity

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in iOS 3.0 and later.

    See Also

    entity (NSManagedObject)

  • A Boolean value that indicates whether the object ID is temporary. (read-only)

    Declaration

    Swift

    var temporaryID: Bool { get }

    Objective-C

    @property(getter=isTemporaryID, readonly) BOOL temporaryID

    Discussion

    YEStrue if the receiver is temporary, otherwise NOfalse. Most object IDs return NOfalse. New objects inserted into a managed object context are assigned a temporary ID which is replaced with a permanent one once the object gets saved to a persistent store.

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in iOS 8.0 and later.

  • The persistent store that fetched the object for the object ID. (read-only)

    Declaration

    Swift

    weak var persistentStore: NSPersistentStore? { get }

    Objective-C

    @property(readonly, weak) NSPersistentStore *persistentStore

    Discussion

    nil if the ID is for a newly-inserted object that has not yet been saved to a persistent store.

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in iOS 3.0 and later.

  • Returns a URI that provides an archiveable reference to the object for the object ID.

    Declaration

    Swift

    func URIRepresentation() -> NSURL

    Objective-C

    - (NSURL *)URIRepresentation

    Return Value

    An NSURL object containing a URI that provides an archiveable reference to the object which the receiver represents.

    Discussion

    If the corresponding managed object has not yet been saved, the object ID (and hence URI) is a temporary value that will change when the corresponding managed object is saved.

    Import Statement

    Objective-C

    @import CoreData;

    Swift

    import CoreData

    Availability

    Available in iOS 3.0 and later.

    See Also

    managedObjectIDForURIRepresentation: (NSPersistentStoreCoordinator)
    objectWithID:: (NSManagedObjectContext)