# \`Sendable\` values in non-\`Sendable\` containers

**URL:** <https://forums.swift.org/t/sendable-values-in-non-sendable-containers/75807>\
**Category:** Using Swift\
**Tags:** concurrency\
**Created:** [November 4, 2024, 11:33am UTC](https://forums.swift.org/t/sendable-values-in-non-sendable-containers/75807 "2024-11-04T11:33:32Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![ole](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ole/32/18720_2.png) [@ole](https://forums.swift.org/u/ole)\
**Post date:** [November 30, 2024, 7:37pm UTC](https://forums.swift.org/t/sendable-values-in-non-sendable-containers/75807/2 "2024-11-30T19:37:53Z")

</div>

It works (I think) if you turn your `var someAsyncValue` into a function and pass the caller's isolation along:

```swift
class Dependency {
    let source = Source()

    func someAsyncValue(isolation: isolated (any Actor)? = #isolation) async -> Int {
        await source.someAsyncValue
    }
}

struct Container {
    let dependency = Dependency()

    @MainActor func worksFineToo() async {
        _ = await self.dependency.someAsyncValue() // ✅
    }
}

```

This compiles in Swift 6 mode and seems to work fine in my very limited testing.

So you have to add a pair of parentheses at the call site and the implementation of the convenience function requires more boilerplate. You have to decide whether this is good enough for you.

Passing a dynamic isolation to computed properties [is mentioned as a future direction in SE-0420](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0420-inheritance-of-actor-isolation.md#syntax-sugar-for-inheriting-actor-isolation). And if [[Pitch] Inherit isolation by default for async functions](https://forums.swift.org/t/pitch-inherit-isolation-by-default-for-async-functions/74862) gets implemented, your code should work as-is, I think.

---

_[View the full topic](https://forums.swift.org/t/sendable-values-in-non-sendable-containers/75807)._
