---
title: viewContext
framework: coredata
role: symbol
role_heading: Instance Property
path: coredata/nspersistentcontainer/viewcontext
---

# viewContext

The main queue’s managed object context.

## Declaration

```swift
var viewContext: NSManagedObjectContext { get }
```

## Mentioned in

Setting up a Core Data stack Syncing a Core Data Store with CloudKit Using Core Data in the background

## Discussion

Discussion This property contains a reference to the NSManagedObjectContext that is created and owned by the persistent container which is associated with the main queue of the application. This context is created automatically as part of the initialization of the persistent container. This context is associated directly with the NSPersistentStoreCoordinator and is non-generational by default.

## See Also

### Acquiring Contexts

- [newBackgroundContext()](coredata/nspersistentcontainer/newbackgroundcontext().md)
