<!--
{
  "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/HKStatisticsCollection/sources()",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "HealthKit"
    ],
    "preciseIdentifier" : "c:objc(cs)HKStatisticsCollection(im)sources"
  },
  "title" : "sources()"
}
-->

# sources()

Returns a set containing all the sources that had samples matched by the statistics collection query.

```
func sources() -> Set<HKSource>
```

## Return Value

A set of sources if the [`separateBySource`](/documentation/HealthKit/HKStatisticsOptions/separateBySource) option was specified; otherwise, it returns `nil`.

## Discussion

If the [`separateBySource`](/documentation/HealthKit/HKStatisticsOptions/separateBySource) option was set, each of the statistics objects returned by the statistics collection also has a [`sources`](/documentation/HealthKit/HKStatistics/sources) array. The statistic object’s array should contain a subset of the sources returned by this method. Specifically, it contains only those sources that contributed samples to that particular statistics object. You can use the source objects in these arrays to request source-specific statistical data.

## See Also

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

An array containing all the sources contributing to these statistics.

[`-  averageQuantityForSource:`](/documentation/HealthKit/HKStatistics/averageQuantity(for:))

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

[`-  sumQuantityForSource:`](/documentation/HealthKit/HKStatistics/sumQuantity(for:))

Returns the sum of all the samples that match the query and that were created by the specified source.

[`-  minimumQuantityForSource:`](/documentation/HealthKit/HKStatistics/minimumQuantity(for:))

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

[`-  maximumQuantityForSource:`](/documentation/HealthKit/HKStatistics/maximumQuantity(for:))

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



---

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)