<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.11.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreData",
  "identifier" : "/documentation/CoreData/NSBatchDeleteRequest",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Core Data"
    ],
    "preciseIdentifier" : "c:objc(cs)NSBatchDeleteRequest"
  },
  "title" : "NSBatchDeleteRequest"
}
-->

# NSBatchDeleteRequest

A request that deletes objects in the SQLite persistent store without loading them into memory.

```
class NSBatchDeleteRequest
```

## Overview

`NSBatchDeleteRequest` — available only when using a SQLite persistent store — deletes managed objects at the SQL level of the persistent store. This request is quicker and more efficient than using a context to fetch a large number of objects into memory, delete them, and then save those deletions back to the store. You create a request using an instance of [`NSFetchRequest`](/documentation/CoreData/NSFetchRequest) that identifies the objects to delete. Alternatively, you can provide an array of identifiers from specific objects of the same entity type; mixing entity types results in an error when you execute the request.

[`NSManagedObjectContext`](/documentation/CoreData/NSManagedObjectContext) doesn’t automatically merge a request’s deletions because they happen at the SQL level. Subsequently, you must remove any deleted objects from memory after the request finishes. To determine the objects a request deletes, configure it to return the [`NSManagedObjectID`](/documentation/CoreData/NSManagedObjectID) of each deleted object and use those identifiers to update your contexts, as the following example shows:

```swift
// Configure the request to return the IDs of the objects it deletes.
request.resultType = .resultTypeObjectIDs

do {
    // Execute the request.
    let deleteResult = try context.execute(request) as? NSBatchDeleteResult
    
    // Extract the IDs of the deleted managed objectss from the request's result.
    if let objectIDs = deleteResult?.result as? [NSManagedObjectID] {
        
        // Merge the deletions into the app's managed object context.
        NSManagedObjectContext.mergeChanges(
            fromRemoteContextSave: [NSDeletedObjectsKey: objectIDs],
            into: [context]
        )
    }
} catch {
    // Handle any thrown errors.
}
```

Alternatively, you can use persistent history tracking to make your contexts aware of changes that happen at the persistent store level. For more information, see [Consuming relevant store changes](/documentation/CoreData/consuming-relevant-store-changes).

> Important:
> Ensure that a request’s changes don’t violate the validation rules in your data model beyond basic delete rules, such as reducing a relationship count below the specified minimum. The Deny delete rule isn’t compatible with `NSBatchDeleteRequest`.

## Topics

### Creating a Request

[`-  initWithFetchRequest:`](/documentation/CoreData/NSBatchDeleteRequest/init(fetchRequest:))

Creates a request that deletes the results of the specified fetch request.

[`-  initWithObjectIDs:`](/documentation/CoreData/NSBatchDeleteRequest/init(objectIDs:))

Creates a request that deletes the managed objects with the specified identifiers.

### Accessing the Fetch Request

[`fetchRequest`](/documentation/CoreData/NSBatchDeleteRequest/fetchRequest)

The fetch request that identifies the managed objects to delete.

### Configuring the Result Type

[`resultType`](/documentation/CoreData/NSBatchDeleteRequest/resultType)

The type of result the request provides when it executes.

[`NSBatchDeleteRequestResultType`](/documentation/CoreData/NSBatchDeleteRequestResultType)

The types of result a batch delete request can provide when it executes.

## Relationships

### Conforms To

[`Hashable`](/documentation/Swift/Hashable)

[`CVarArg`](/documentation/Swift/CVarArg)

[`NSCopying`](/documentation/Foundation/NSCopying)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`Equatable`](/documentation/Swift/Equatable)

### Inherits From

[`NSPersistentStoreRequest`](/documentation/CoreData/NSPersistentStoreRequest)

---

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)