---
title: managedObjectContext
framework: appkit
role: symbol
role_heading: Instance Property
path: appkit/nspersistentdocument/managedobjectcontext
---

# managedObjectContext

The managed object context for the document.

## Declaration

```swift
var managedObjectContext: NSManagedObjectContext? { get set }
```

## Discussion

Discussion If a managed object context for the document does not exist, one is created automatically. If you want to customize the creation of the persistence stack, reimplement this property in your custom subclass and use your implementation to create the appropriate objects.

## See Also

### Related Documentation

- [Core Data Programming Guide](apple-archive/documentation/Cocoa/Conceptual/CoreData.md)
- [Document-Based App Programming Guide for Mac](apple-archive/documentation/DataManagement/Conceptual/DocBasedAppProgrammingGuideForOSX/Introduction.md)

### Managing the Persistence Objects

- [managedObjectModel](appkit/nspersistentdocument/managedobjectmodel.md)
- [configurePersistentStoreCoordinator(for:ofType:modelConfiguration:storeOptions:)](appkit/nspersistentdocument/configurepersistentstorecoordinator(for:oftype:modelconfiguration:storeoptions:).md)
- [persistentStoreType(forFileType:)](appkit/nspersistentdocument/persistentstoretype(forfiletype:).md)
