Contents

object(with:)

Returns either an existing object from the context or a fault that represents that object.

Declaration

func object(with objectID: NSManagedObjectID) -> NSManagedObject

Parameters

  • objectID:

    The identifier of the object to retrieve. For more information, see Nsmanagedobjectid.

Return Value

The identified object, if its known to the context; otherwise, a fault with its objectID property set to objectID.

Discussion

If the context doesn’t recognize the specified object, this method returns a fault — a placeholder object that doesn’t load its properties until your code accesses them. The context then fetches the corresponding values from the persistent store and uses those values to turn the fault into a fully realized object.

When this method returns a fault, Core Data makes no attempts to verify the existence of the underlying object in the persistent store. If the object doesn’t exist when the context tries to the fetch the object’s values, the framework throws an exception.

See Also

Registering and fetching objects