<!--
{
  "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/CLSActivity",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "ClassKit"
    ],
    "preciseIdentifier" : "c:objc(cs)CLSActivity"
  },
  "title" : "CLSActivity"
}
-->

# CLSActivity

A representation of user interaction with a context.

```
class CLSActivity
```

## Overview

An activity represents a student’s attempt to complete the task corresponding to a [`CLSContext`](/documentation/ClassKit/CLSContext) instance. For example, if a context represents a quiz, the associated activity represents the student’s attempt to take the quiz. As such, an activity is always associated with a context. You never initialize an activity in isolation or store a reference to it. Rather, you ask a context to create the activity and retrieve it from the context.

### Starting and Stopping Activities

You start the activity with a call to the [`start()`](/documentation/ClassKit/CLSActivity/start()) method when the user begins the task, and stop it with a call to the [`stop()`](/documentation/ClassKit/CLSActivity/stop()) method when the user finishes. You can also use the [`stop()`](/documentation/ClassKit/CLSActivity/stop()) method to stop it temporarily if the user pauses the task, in which case you can start it again later with another call to [`start()`](/documentation/ClassKit/CLSActivity/start()) when the user resumes. The activity keeps track of the total time spent in the running state, which you can read via the [`duration`](/documentation/ClassKit/CLSActivity/duration) property.

Whether you implement activity pausing depends on how the parts of your app work. For example, you might pause a game activity when the user presses the pause button to reflect that the user has stepped away from the activity, but is likely to return soon to complete the task. On the other hand, you might not provide a way to pause a quiz activity because you require that it be completed without interruption, once started. If you do pause, you can start and stop an activity as many times as you want, but when you create a new activity (representing a new attempt at a task), you can no longer access the older activity from your app.

### Recording Progress

You can also assign [`progress`](/documentation/ClassKit/CLSActivity/progress) to an activity. How you define progress depends on the task. For example, you can record progress through a quiz as a fraction of questions answered, or progress through a game level as a fraction of obstacles overcome.

To record additional metrics, you attach [`CLSActivityItem`](/documentation/ClassKit/CLSActivityItem) instances to an activity. For example, you can add both a score and a count of hints used to a quiz activity. To feature one of these items prominently, make it the [`primaryActivityItem`](/documentation/ClassKit/CLSActivity/primaryActivityItem).

## Topics

### Starting and stopping an activity

[`-  start`](/documentation/ClassKit/CLSActivity/start())

Tells an activity to start recording duration and progress for a task.

[`-  stop`](/documentation/ClassKit/CLSActivity/stop())

Tells an activity to stop or pause recording duration and progress for a task.

[`started`](/documentation/ClassKit/CLSActivity/isStarted)

A Boolean that indicates whether an activity is running.

[`duration`](/documentation/ClassKit/CLSActivity/duration)

The cumulative time in seconds that an activity has been active.

### Measuring progress

[`progress`](/documentation/ClassKit/CLSActivity/progress)

A measure of progress through the task, given as a fraction in the range [0, 1].

[`-  addProgressRangeFromStart:toEnd:`](/documentation/ClassKit/CLSActivity/addProgressRange(fromStart:toEnd:))

Adds a progress range to a given activity.

### Managing activity items

[`-  addAdditionalActivityItem:`](/documentation/ClassKit/CLSActivity/addAdditionalActivityItem(_:))

Adds an activity item to an activity.

[`primaryActivityItem`](/documentation/ClassKit/CLSActivity/primaryActivityItem)

Adds an activity item to an activity and sets it as the primary activity item.

[`additionalActivityItems`](/documentation/ClassKit/CLSActivity/additionalActivityItems)

The list of activity items associated with an activity.

[`-  removeAllActivityItems`](/documentation/ClassKit/CLSActivity/removeAllActivityItems())

Deletes all activity items associated with the current activity.

## Relationships

### Conforms To

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

[`NSSecureCoding`](/documentation/Foundation/NSSecureCoding)

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

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

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

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

[`NSCoding`](/documentation/Foundation/NSCoding)

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

### Inherits From

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

---

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)