<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreData",
  "identifier" : "/documentation/CoreData/NSBatchInsertRequest/init(entityName:managedObjectHandler:)-7dr6p",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Core Data"
    ],
    "preciseIdentifier" : "c:objc(cs)NSBatchInsertRequest(cm)batchInsertRequestWithEntityName:managedObjectHandler:"
  },
  "title" : "init(entityName:managedObjectHandler:)"
}
-->

# init(entityName:managedObjectHandler:)

Creates a batch-insertion request for a named managed entity, and specifies a closure that inserts data into the entity.

```
convenience init(entityName: String, managedObjectHandler handler: @escaping (NSManagedObject) -> Bool)
```

## Parameters

`entityName`

The name of the managed entity that defines the object to create.

`handler`

A closure that inserts data into the managed entity.

## Return Value

A batch-insertion request.

## Discussion

Core Data repeatedly calls the provided closure until it returns `true`, then finishes the request and saves the data.

---

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)