<!--
{
  "availability" : [
    "iOS: 5.0.0 -",
    "iPadOS: 5.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.7.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreData",
  "identifier" : "/documentation/CoreData/NSPersistentStoreCoordinator/execute(_:with:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Core Data"
    ],
    "preciseIdentifier" : "c:objc(cs)NSPersistentStoreCoordinator(im)executeRequest:withContext:error:"
  },
  "title" : "execute(_:with:)"
}
-->

# execute(_:with:)

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

```
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

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

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

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)