<!--
{
  "availability" : [
    "iOS: 3.0.0 -",
    "iPadOS: 3.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.4.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreData",
  "identifier" : "/documentation/CoreData/NSManagedObjectContext/assign(_:to:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Core Data"
    ],
    "preciseIdentifier" : "c:objc(cs)NSManagedObjectContext(im)assignObject:toPersistentStore:"
  },
  "title" : "assign(_:to:)"
}
-->

# assign(_:to:)

Specifies the store in which a newly inserted object will be saved.

```
func assign(_ object: Any, to store: NSPersistentStore)
```

## Parameters

`object`

A managed object.

`store`

A persistent store.

## Discussion

You can obtain a store from the persistent store coordinator, using for example [`persistentStore(for:)`](/documentation/CoreData/NSPersistentStoreCoordinator/persistentStore(for:)).

### Special Considerations

It is only necessary to use this method if the receiver’s persistent store coordinator manages multiple writable stores that have `object`‘s entity in their configuration. Maintaining configurations in the managed object model can eliminate the need for invoking this method directly in many situations. If the receiver’s persistent store coordinator manages only a single writable store, or if only one store has `object`’s entity in its model, `object` will automatically be assigned to that store.

## See Also

[`persistentStoreCoordinator`](/documentation/CoreData/NSManagedObjectContext/persistentStoreCoordinator)

The persistent store coordinator of the context.



---

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)