---
title: "assign(_:to:)"
framework: coredata
role: symbol
role_heading: Instance Method
path: "coredata/nsmanagedobjectcontext/assign(_:to:)"
---

# assign(_:to:)

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

## Declaration

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

## Parameters

- `object`: A managed object.
- `store`: A persistent store.

## Discussion

Discussion You can obtain a store from the persistent store coordinator, using for example 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

### Related Documentation

- [persistentStoreCoordinator](coredata/nsmanagedobjectcontext/persistentstorecoordinator.md)

### Handling managed objects

- [shouldDeleteInaccessibleFaults](coredata/nsmanagedobjectcontext/shoulddeleteinaccessiblefaults.md)
- [insertedObjects](coredata/nsmanagedobjectcontext/insertedobjects.md)
- [updatedObjects](coredata/nsmanagedobjectcontext/updatedobjects.md)
- [deletedObjects](coredata/nsmanagedobjectcontext/deletedobjects.md)
- [shouldHandleInaccessibleFault(_:for:triggeredByProperty:)](coredata/nsmanagedobjectcontext/shouldhandleinaccessiblefault(_:for:triggeredbyproperty:).md)
- [insert(_:)](coredata/nsmanagedobjectcontext/insert(_:).md)
- [delete(_:)](coredata/nsmanagedobjectcontext/delete(_:).md)
- [obtainPermanentIDs(for:)](coredata/nsmanagedobjectcontext/obtainpermanentids(for:).md)
- [detectConflicts(for:)](coredata/nsmanagedobjectcontext/detectconflicts(for:).md)
- [refresh(_:mergeChanges:)](coredata/nsmanagedobjectcontext/refresh(_:mergechanges:).md)
- [processPendingChanges()](coredata/nsmanagedobjectcontext/processpendingchanges().md)
- [observeValue(forKeyPath:of:change:context:)](coredata/nsmanagedobjectcontext/observevalue(forkeypath:of:change:context:).md)
