<!--
{
  "availability" : [
    "iOS: 8.0.0 - 17.0.0",
    "iPadOS: 8.0.0 - 17.0.0",
    "macCatalyst: 13.0.0 - 16.0.0",
    "macOS: 13.0.0 - 14.0.0",
    "visionOS: 1.0.0 - 1.0.0",
    "watchOS: 2.0.0 - 10.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "HealthKit",
  "identifier" : "/documentation/HealthKit/HKWorkout/init(activityType:start:end:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "HealthKit"
    ],
    "preciseIdentifier" : "c:objc(cs)HKWorkout(cm)workoutWithActivityType:startDate:endDate:"
  },
  "title" : "init(activityType:start:end:)"
}
-->

# init(activityType:start:end:)

Instantiates a new workout.

```
convenience init(activityType workoutActivityType: HKWorkoutActivityType, start startDate: Date, end endDate: Date)
```

## Parameters

`workoutActivityType`

The type of activity being performed during the workout. For a list of possible activity types, see [`HKWorkoutActivityType`](/documentation/HealthKit/HKWorkoutActivityType).

`startDate`

The date and time when the activity started.

`endDate`

The date and time when the activity ended. This date must be equal to or later than the start date.

## Return Value

A workout activity.

## Discussion

The workout’s duration is calculated from its start and end times. The workout’s total distance, total energy burned, workout events, device, and metadata are all set to `nil`.

```swift
let basketball = HKWorkout(activityType:HKWorkoutActivityType.Basketball,
                           startDate: start, endDate: end)
 
 
healthStore.saveObject(basketball) { (success, error) -> Void in
    guard success else {
        // Perform proper error handling here...
        fatalError("*** An error occurred while saving this " +
            "workout: \(error?.localizedDescription)")
    }
}
```

## See Also

[`workoutActivityType`](/documentation/HealthKit/HKWorkout/workoutActivityType)

The type of activity performed during the workout.

[`totalDistance`](/documentation/HealthKit/HKWorkout/totalDistance)

The total distance traveled during the workout.

[`duration`](/documentation/HealthKit/HKWorkout/duration)

The workout’s duration.

[`metadata`](/documentation/HealthKit/HKObject/metadata)

The metadata for this HealthKit object.

[`totalEnergyBurned`](/documentation/HealthKit/HKWorkout/totalEnergyBurned)

The total active energy burned during the workout.

[`workoutEvents`](/documentation/HealthKit/HKWorkout/workoutEvents)

An array of workout event objects.



---

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)