<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: 14.0.0 -",
    "macOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 7.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "HealthKit",
  "identifier" : "/documentation/HealthKit/HKQuery/predicateForElectrocardiograms(classification:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "HealthKit"
    ],
    "preciseIdentifier" : "c:objc(cs)HKQuery(cm)predicateForElectrocardiogramsWithClassification:"
  },
  "title" : "predicateForElectrocardiograms(classification:)"
}
-->

# predicateForElectrocardiograms(classification:)

Returns a predicate that matches electrocardiogram samples with the specified classification.

```
class func predicateForElectrocardiograms(classification: HKElectrocardiogram.Classification) -> NSPredicate
```

## Parameters

`classification`

The target classification.

## Return Value

A predicate that matches electrocardiogram samples with the specified classification.

## Discussion

Use this convenience method to create a predicate that matches electrocardiogram samples with the specified classification. The following sample uses both the convenience method and a predicate format string to create equivalent predicates.

```swift
let forClassification = HKQuery.predicateForElectrocardiograms(classification: .atrialFibrillation)

let classification = HKElectrocardiogram.Classification.atrialFibrillation.rawValue

let explicitForClassification = NSPredicate(format: "%K == %d", HKPredicateKeyPathECGClassification, classification)
```

## See Also

[`let HKPredicateKeyPathECGClassification: String`](/documentation/HealthKit/HKPredicateKeyPathECGClassification)

The key path for the sample’s classification.



---

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)