<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "HealthKit",
  "identifier" : "/documentation/HealthKit/HKStatistics/maximumQuantity(for:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "HealthKit"
    ],
    "preciseIdentifier" : "c:objc(cs)HKStatistics(im)maximumQuantityForSource:"
  },
  "title" : "maximumQuantity(for:)"
}
-->

# maximumQuantity(for:)

Returns the maximum value from all the samples that match the query and that were created by the specified source.

```
func maximumQuantity(for source: HKSource) -> HKQuantity?
```

## Parameters

`source`

A data source from the statistics object’s [`sources`](/documentation/HealthKit/HKStatistics/sources) array.

## Return Value

If both the [`discreteMax`](/documentation/HealthKit/HKStatisticsOptions/discreteMax) option and the [`separateBySource`](/documentation/HealthKit/HKStatisticsOptions/separateBySource) option were set, this method returns a quantity object. This object contains the maximum value from all the samples that match the query and were created by the specified source. If the statistics options were not both set, this method returns `nil`.

## See Also

[`endDate`](/documentation/HealthKit/HKStatistics/endDate)

The end of the time period included in these statistics.

[`sources`](/documentation/HealthKit/HKStatistics/sources)

An array containing all the sources contributing to these statistics.

[`startDate`](/documentation/HealthKit/HKStatistics/startDate)

The start of the time period included in these statistics.



---

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)