<!--
{
  "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/NSIncrementalStore/newObjectID(for:referenceObject:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Core Data"
    ],
    "preciseIdentifier" : "c:objc(cs)NSIncrementalStore(im)newObjectIDForEntity:referenceObject:"
  },
  "title" : "newObjectID(for:referenceObject:)"
}
-->

# newObjectID(for:referenceObject:)

Returns a new object ID that uses given data as the key.

```
func newObjectID(for entity: NSEntityDescription, referenceObject data: Any) -> NSManagedObjectID
```

## Parameters

`entity`

The entity for the new object ID.

`data`

An object of type <doc://com.apple.documentation/documentation/Foundation/NSString> or <doc://com.apple.documentation/documentation/Foundation/NSNumber> to use as the key.

## Return Value

A new object ID for an instance of the entity specified by `entity` and that uses `data` as the key.

## Discussion

You should not override this method.

---

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)