<!--
{
  "availability" : [
    "iOS: 11.3.0 -",
    "iPadOS: 11.3.0 -",
    "macCatalyst: 11.3.0 -",
    "macOS: 11.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "ClassKit",
  "identifier" : "/documentation/ClassKit/CLSDataStore",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "ClassKit"
    ],
    "preciseIdentifier" : "c:objc(cs)CLSDataStore"
  },
  "title" : "CLSDataStore"
}
-->

# CLSDataStore

A container for all the ClassKit data in your app.

```
class CLSDataStore
```

## Overview

Use the ClassKit data store to build and access contexts ([`CLSContext`](/documentation/ClassKit/CLSContext) instances) that you use to advertise your app’s assignable content. Contexts in turn provide access to activities ([`CLSActivity`](/documentation/ClassKit/CLSActivity) instances) and activity items ([`CLSScoreItem`](/documentation/ClassKit/CLSScoreItem), [`CLSBinaryItem`](/documentation/ClassKit/CLSBinaryItem), and [`CLSQuantityItem`](/documentation/ClassKit/CLSQuantityItem) instances) that you use to record progress through assignments. You don’t instantiate a data store yourself. Instead, use the single [`shared`](/documentation/ClassKit/CLSDataStore/shared) data store instance throughout your app.

The data store provides access to the app’s one and only main context through the [`mainAppContext`](/documentation/ClassKit/CLSDataStore/mainAppContext) property. This property acts as the root context in your context hierarchy that you can use as a starting point when searching for descendant contexts.

To build contexts, you adopt the [`CLSDataStoreDelegate`](/documentation/ClassKit/CLSDataStoreDelegate) protocol in one of your classes, typically one that exists for the lifetime of your app, and assign an instance of that class as the shared data store’s [`delegate`](/documentation/ClassKit/CLSDataStore/delegate) property. Then, when the data store needs a context that it’s never seen before, it asks your delegate to build it.

After you make changes to any context, activity, or activity item, call the data store’s [`save(completion:)`](/documentation/ClassKit/CLSDataStore/save(completion:)) method to commit the changes, and propagate them through the network.

## Topics

### Accessing the shared data store

[`shared`](/documentation/ClassKit/CLSDataStore/shared)

The shared data store object.

### Managing the delegate

  <doc://com.apple.classkit/documentation/ClassKit/building-missing-contexts>

[`delegate`](/documentation/ClassKit/CLSDataStore/delegate)

The data store delegate instance.

[`CLSDataStoreDelegate`](/documentation/ClassKit/CLSDataStoreDelegate)

An interface the data store uses to request new contexts.

### Accessing specific contexts and activities

[`mainAppContext`](/documentation/ClassKit/CLSDataStore/mainAppContext)

The app’s top-level context.

[`activeContext`](/documentation/ClassKit/CLSDataStore/activeContext)

The currently active context.

[`runningActivity`](/documentation/ClassKit/CLSDataStore/runningActivity)

The currently running activity within the currently active context.

[`-  fetchActivityForURL:completion:`](/documentation/ClassKit/CLSDataStore/fetchActivity(for:completion:))

Fetches an activity for a given document so you can record progress on the associated task.

[`-  completeAllAssignedActivitiesMatching:`](/documentation/ClassKit/CLSDataStore/completeAllAssignedActivities(matching:))

Marks all of the assigned and active activities for the given context path as complete.

### Finding contexts that match criteria

[`-  contextsMatchingIdentifierPath:completion:`](/documentation/ClassKit/CLSDataStore/contexts(matchingIdentifierPath:completion:))

Fetches all the contexts along a given identifier path.

[`-  contextsMatchingPredicate:completion:`](/documentation/ClassKit/CLSDataStore/contexts(matching:completion:))

Fetches all the contexts matching a predicate.

[`CLSPredicateKeyPath`](/documentation/ClassKit/CLSPredicateKeyPath)

The set of possible key paths you use to search for contexts.

### Removing contexts

[`-  removeContext:`](/documentation/ClassKit/CLSDataStore/remove(_:))

Marks a context for removal.

### Saving changes

[`-  saveWithCompletion:`](/documentation/ClassKit/CLSDataStore/save(completion:))

Saves any changes you’ve made in the data store.

## Relationships

### Conforms To

[`Hashable`](/documentation/Swift/Hashable)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`Equatable`](/documentation/Swift/Equatable)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`CVarArg`](/documentation/Swift/CVarArg)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

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)