---
title: "existingObject(with:)"
framework: coredata
role: symbol
role_heading: Instance Method
path: "coredata/nsmanagedobjectcontext/existingobject(with:)"
---

# existingObject(with:)

Returns an existing object from either the context or the persistent store.

## Declaration

```swift
func existingObject(with objectID: NSManagedObjectID) throws -> NSManagedObject
```

## Parameters

- `objectID`: The identifier of the object to retrieve. For more information, see doc://com.apple.coredata/documentation/CoreData/NSManagedObjectID.

## Return Value

Return Value The identified object from either the context or the persistent store.

## Discussion

Discussion If the context recognizes the specified object, the method returns that object. Otherwise, the context fetches and returns a fully realized object from the persistent store; unlike object(with:), this method never returns a fault. If the object doesn’t exist in both the context and the persistent store, the method throws an error.

## See Also

### Registering and fetching objects

- [fetch(_:)](coredata/nsmanagedobjectcontext/fetch(_:)-38ys1.md)
- [fetch(_:)](coredata/nsmanagedobjectcontext/fetch(_:)-4xeoz.md)
- [count(for:)](coredata/nsmanagedobjectcontext/count(for:)-93zbm.md)
- [registeredObject(for:)](coredata/nsmanagedobjectcontext/registeredobject(for:).md)
- [object(with:)](coredata/nsmanagedobjectcontext/object(with:).md)
- [registeredObjects](coredata/nsmanagedobjectcontext/registeredobjects.md)
- [count(for:)](coredata/nsmanagedobjectcontext/count(for:)-3r91z.md)
- [execute(_:)](coredata/nsmanagedobjectcontext/execute(_:).md)
- [refreshAllObjects()](coredata/nsmanagedobjectcontext/refreshallobjects().md)
- [retainsRegisteredObjects](coredata/nsmanagedobjectcontext/retainsregisteredobjects.md)
