---
title: "execute(_:with:)"
framework: coredata
role: symbol
role_heading: Instance Method
path: "coredata/nspersistentstorecoordinator/execute(_:with:)"
---

# execute(_:with:)

Executes the specified request on each of the coordinator’s persistent stores.

## Declaration

```swift
func execute(_ request: NSPersistentStoreRequest, with context: NSManagedObjectContext) throws -> Any
```

## Parameters

- `request`: A fetch or save request.
- `context`: The context against which request should be executed.

## Return Value

Return Value An array containing managed objects, managed object IDs, or dictionaries as appropriate for a fetch request; an empty array if request is a save request, or nil if an error occurred.

## Discussion

Discussion User defined requests return arrays of arrays, where a nested array is the result returned from a single store.

## See Also

### Performing tasks

- [perform(_:)](coredata/nspersistentstorecoordinator/perform(_:)-74udx.md)
- [performAndWait(_:)](coredata/nspersistentstorecoordinator/performandwait(_:)-15ude.md)
- [perform(_:)](coredata/nspersistentstorecoordinator/perform(_:)-7jqb.md)
- [performAndWait(_:)](coredata/nspersistentstorecoordinator/performandwait(_:)-d3kq.md)
