<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macCatalyst: 27.0.0 -",
    "macOS: 27.0.0 -",
    "tvOS: 27.0.0 -",
    "visionOS: 27.0.0 -",
    "watchOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/Task/hasActiveCancellationShield",
  "metadataVersion" : "0.1.0",
  "role" : "Type Property",
  "symbol" : {
    "kind" : "Type Property",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:ScT12_Concurrencys5NeverORszACRs_rlE27hasActiveCancellationShieldSbvpZ"
  },
  "title" : "hasActiveCancellationShield"
}
-->

# hasActiveCancellationShield

Checks if the current task is executing in a scope with a task cancellation shield activated by the
`withTaskCancellationShield(operation:)-(()->Value)` function.

```
static var hasActiveCancellationShield: Bool { get }
```

## Discussion

An active task cancellation shield prevents a task’s ability to observe if it was cancelled,
i.e. the [`isCancelled`](/documentation/Swift/Task/isCancelled-swift.type.property) property will always return `false` when the task is executing
with an active shield.

This property is primarily aimed at  debugging and understanding cancellation behavior
in complex call hierarchies, and should not be used in regular control flow.

Returns `true` when executing within a task that has an active cancellation shield.

Cancellation shields are not automatically inherited by child tasks; each child task must install
its own shield if needed if it, independently, wanted to ignore cancellation during a specific scope.

> SeeAlso: ``withTaskCancellationShield(operation:)-(()->Value)``

> SeeAlso: ``doc://com.apple.Swift/documentation/Swift/UnsafeCurrentTask/hasActiveCancellationShield``

---

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)