---
title: Getting non-Sendable values out of actors (NonSendableExitingActor)
framework: Swift Compiler
role: article
role_heading: Article
path: swift-compiler/documentation/diagnostics/getting-non-sendable-values-out-of-actors
---

# Getting non-Sendable values out of actors (NonSendableExitingActor)

## Overview

Overview When an actor is used to protect a non-Sendable value, the compiler will enforce that the non-Sendable value remains in the actor instance’s isolation. Accessing an actor’s property of non-Sendable type from a different isolation will be diagnosed when complete concurrency checking is enabled. This is an error in the Swift 6 language mode. For example: class Plant {     var height = 0 }

actor Terrarium {     var label = "Yarrow"     let plant = Plant() }

nonisolated func growAndReport(in terrarium: Terrarium, by amount: Int) async {     let label = await terrarium.label // Fine, `label` is Sendable.     let plant = await terrarium.plant // error: non-Sendable type 'Plant' of property 'plant' cannot exit actor-isolated context     plant.height += amount     print("\(label) is now \(plant.height) cm tall") } Non-Sendable types in actor-isolated properties can’t be safely accessed concurrently, even when declared with let. This is because a let declaration can hold a type with internal mutable state, like Plant‘s height in the above example. Letting a Plant reference exit the Terrarium instance’s isolation would allow concurrent mutation, which is a data race. A useful pattern when working with actors is to only use Sendable types to get information in and out of the actor. You may be able to achieve this by writing the functions directly in the actor: class Plant {     var height = 0 }

actor Terrarium {     var label = "Yarrow"     let plant = Plant()

func growAndReport(by amount: Int) { // amount is an Int, which is Sendable         plant.height += amount // OK         print("\(label) is now \(plant.height) cm tall")     } } Or, if using a global actor like @MainActor, by isolating the functions that access the non-Sendable values to that global actor, so those values never have to leave their isolation: class Plant {     var height = 0 }

@MainActor final class Terrarium {     var label = "Yarrow"     let plant = Plant() }

@MainActor func growAndReport(in terrarium: Terrarium, by amount: Int) {     let plant = terrarium.plant // OK     plant.height += amount     print("\(terrarium.label) is now \(plant.height) cm tall") } By moving entire functions into actor-isolated code, you may also be able to reduce the number of suspension points, or even make the function synchronous. This can result in simpler code, as the compiler guarantees that no other code can modify the actor-protected state while you are running code synchronously on that actor. Once you’re willing to reconsider which isolation Terrarium belongs to, as in the @MainActor example above, it’s worth also considering whether Terrarium needs isolation at all. In some cases your type may already be used without being sent, and does not need to be Sendable or isolated. The compiler will still ensure callers of Terrarium protect it, pushing the problem up a level: class Plant {     var height = 0 }

class Terrarium {     var label = "Yarrow"     let plant = Plant() }

nonisolated func growAndReport(in terrarium: Terrarium, by amount: Int) {     let label = terrarium.label     let plant = terrarium.plant     plant.height += amount     print("\(label) is now \(plant.height) cm tall") }

## See Also

- [@dynamicCallable implementation requirements (DynamicCallable)](swift-compiler/documentation/diagnostics/dynamic-callable-requirements.md)
- [Actors can’t conform to global actor protocols (ActorConformanceToGlobalActorProtocol)](swift-compiler/documentation/diagnostics/actors-cannot-conform-to-global-actor-protocols.md)
- [Add @preconcurrency import (AddPreconcurrencyImport)](swift-compiler/documentation/diagnostics/add-preconcurrency-import.md)
- [Always enabled availability domains (AlwaysAvailableDomain)](swift-compiler/documentation/diagnostics/always-available-domain.md)
- [Argument matching for trailing closures (TrailingClosureMatching)](swift-compiler/documentation/diagnostics/trailing-closure-matching.md)
- [Calling a mutating async actor-isolated method (ActorIsolatedMutatingAsync)](swift-compiler/documentation/diagnostics/actor-isolated-mutating-async.md)
- [Calling an actor-isolated method from a synchronous nonisolated context (ActorIsolatedCall)](swift-compiler/documentation/diagnostics/actor-isolated-call.md)
- [Captures in a `@Sendable` closure (SendableClosureCaptures)](swift-compiler/documentation/diagnostics/sendable-closure-captures.md)
- [Compilation caching (CompilationCaching)](swift-compiler/documentation/diagnostics/compilation-caching.md)
- [Conforming to `StringInterpolationProtocol` (StringInterpolationConformance)](swift-compiler/documentation/diagnostics/string-interpolation-conformance.md)
- [Conversion from `@isolated(any)` function type to synchronous function type (ConversionFromIsolatedAnyToSynchronous)](swift-compiler/documentation/diagnostics/conversion-from-isolated-any-to-synchronous.md)
- [Cross-isolation data race (RegionIsolationCrossIsolationDataRace)](swift-compiler/documentation/diagnostics/region-isolation-cross-isolation-data-race.md)
- [Deprecated declaration warnings (DeprecatedDeclaration)](swift-compiler/documentation/diagnostics/deprecated-declaration.md)
- [Deprecated implementation-only imports (ImplementationOnlyDeprecated)](swift-compiler/documentation/diagnostics/implementation-only-deprecated.md)
- [Dynamic exclusivity (DynamicExclusivity)](swift-compiler/documentation/diagnostics/dynamic-exclusivity.md)
