---
title: "init(type:value:start:end:)"
framework: healthkit
role: symbol
role_heading: Initializer
path: "healthkit/hkcategorysample/init(type:value:start:end:)"
---

# init(type:value:start:end:)

Creates a newly instantiated category sample.

## Declaration

```swift
convenience init(type: HKCategoryType, value: Int, start startDate: Date, end endDate: Date)
```

## Parameters

- `type`: The category type for this sample. For a complete list, see doc://com.apple.healthkit/documentation/HealthKit/HKCategoryTypeIdentifier.
- `value`: The value for this sample. This value must come from the appropriate category value enumeration. Each category type uses its own enumeration. For more information, see doc://com.apple.healthkit/documentation/HealthKit/HKCategoryTypeIdentifier.
- `startDate`: The start date for the sample. This must be equal to or earlier than the end date; otherwise, this method throws an exception (doc://com.apple.documentation/documentation/Foundation/NSExceptionName/invalidArgumentException).
- `endDate`: The end date for the sample. This must be equal to or later than the start date; otherwise, this method throws an exception (doc://com.apple.documentation/documentation/Foundation/NSExceptionName/invalidArgumentException).

## Return Value

Return Value A valid category sample.

## Discussion

Discussion HealthKit uses category samples to represent data that can be classified into a finite set of categories. To create a category sample, you must first create the corresponding category type, and then set its start and end dates, as shown below.

## See Also

### Related Documentation

- [value](healthkit/hkcategorysample/value.md)
- [categoryType(forIdentifier:)](healthkit/hkobjecttype/categorytype(foridentifier:).md)
- [endDate](healthkit/hksample/enddate.md)
- [categoryType](healthkit/hkcategorysample/categorytype.md)
- [startDate](healthkit/hksample/startdate.md)

### Creating Category Samples

- [init(type:value:start:end:metadata:)](healthkit/hkcategorysample/init(type:value:start:end:metadata:).md)
- [init(type:value:start:end:device:metadata:)](healthkit/hkcategorysample/init(type:value:start:end:device:metadata:).md)
