A container for all the ClassKit data in your app.


class CLSDataStore : NSObject


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

The data store provides access to the app’s one and only main context through the 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 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 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:) method to commit the changes, and propagate them through the network.


Accessing the Shared Data Store

class var shared: CLSDataStore

The shared data store object.

Managing the Delegate

Building Missing Contexts

Create and initialize missing contexts.

var delegate: CLSDataStoreDelegate?

The data store delegate instance.

protocol CLSDataStoreDelegate

An interface the data store uses to request new contexts.

Accessing Specific Contexts and Activities

var mainAppContext: CLSContext

The app’s top-level context.

var activeContext: CLSContext?

The currently active context.

var runningActivity: CLSActivity?

The currently running activity within the currently active context.

func completeAllAssignedActivities(matching: [String])

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

Finding Contexts That Match Criteria

struct CLSPredicateKeyPath

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

Removing Contexts

func remove(CLSContext)

Marks a context for removal.

Saving Changes

func save(completion: ((Error?) -> Void)?)

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


Inherits From

Conforms To

See Also


Enabling ClassKit in Your App

Prepare your app and your development environment to adopt ClassKit.

ClassKit Environment Entitlement

The ClassKit development or production environment for an education app that works with the Schoolwork app.

Incorporating ClassKit into an Educational App

Walk through the process of setting up assignments and recording student progress.