# Isolated type vs. Sendable isolated type

**URL:** <https://forums.swift.org/t/isolated-type-vs-sendable-isolated-type/88108>\
**Category:** Using Swift\
**Tags:** concurrency, actors\
**Created:** [July 7, 2026, 2:19pm UTC](https://forums.swift.org/t/isolated-type-vs-sendable-isolated-type/88108 "2026-07-07T14:19:52Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![a7medev](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/a7medev/32/39903_2.png) [@a7medev](https://forums.swift.org/u/a7medev)\
**Post date:** [July 7, 2026, 2:19pm UTC](https://forums.swift.org/t/isolated-type-vs-sendable-isolated-type/88108/1 "2026-07-07T14:19:52Z")

</div>

Why does this code compile:

```swift
@MainActor
protocol P: Sendable {}

@MainActor
class C {
    let p: any P
    
    nonisolated init(p: any P) {
        self.p = p
    }
}

```

While this does not?

```swift
@MainActor
protocol P {}

@MainActor
class C {
    let p: any P
    
    nonisolated init(p: any P) {
        self.p = p // Main actor-isolated property 'p' can not be mutated from a nonisolated context
    }
}

```

Isn't an actor-isolated type already `Sendable` by definition?

---

<div class="post-metadata">

**Author:** ![atifdev10](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/atifdev10/32/44025_2.png) [@atifdev10](https://forums.swift.org/u/atifdev10)\
**Post date:** [July 7, 2026, 2:57pm UTC](https://forums.swift.org/t/isolated-type-vs-sendable-isolated-type/88108/2 "2026-07-07T14:57:57Z")

</div>

> [@a7medev](#):
>
> Isn't an actor-isolated type already `Sendable` by definition?

According to my knowledge, this does not apply to protocols. Global actor isolated protocols just means the requirements need to be isoalted to that actor, not the type itself:

```swift
@MainActor
protocol P1 {
    var a: Int { get set }
}
// Means:*
protocol P1 {
    @MainActor var a: Int { get set }
}

```

For example:

```swift
@globalActor
actor DatabaseActor {
    static let shared = DatabaseActor()
}

@MainActor
protocol P1 {
    var a: Int { get set }
}

@DatabaseActor
protocol P2 {
    var b: Int { get set }
}

final class P1P2Conformer: P1, P2 {
    var a: Int = 1 // isolated to MainActor
    var b: Int = 2 // isolated to DatabaseActor
    var c: Int = 2 // nonisolated**
}

```

\*: There is a small difference between the two. The first one - if there are no other protocols like this that are isoalted to a different global actor - will make the entire type isolated to it. The second doesn't.

\*\*: Normally the isolation would've been inherited from the conformance and make this also isolated. But since there are 2 different isoaltion domains the compiler makes it nonisoalted.

* * *

Also the requirements can be satisfied with nonisolated members:

```swift
nonisolated final class NonisolatedP1P2Conformer: P1, P2 {
    var a: Int = 1
    var b: Int = 2
}

```

---

<div class="post-metadata">

**Author:** ![NotTheNHK](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/notthenhk/32/43199_2.png) [@NotTheNHK](https://forums.swift.org/u/NotTheNHK)\
**Post date:** [July 7, 2026, 3:01pm UTC](https://forums.swift.org/t/isolated-type-vs-sendable-isolated-type/88108/3 "2026-07-07T15:01:11Z")

</div>

The protocol `P` itself does not become isolated to `@MainActor`. All it does is make any members of `P` `@MainActor` isolated by default, but not the protocol itself. Ms. Borla already gave an excellent answer in this thread: [Global actor isolated protocols and SendableMetatype - #2 by hborla](https://forums.swift.org/t/global-actor-isolated-protocols-and-sendablemetatype/84307/2)

---

<div class="post-metadata">

**Author:** ![mattie](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mattie/32/13267_2.png) [@mattie](https://forums.swift.org/u/mattie)\
**Post date:** [July 7, 2026, 3:32pm UTC](https://forums.swift.org/t/isolated-type-vs-sendable-isolated-type/88108/4 "2026-07-07T15:32:53Z")

</div>

This is tricky one. But it helped me quite a bit to see a concrete example:

```swift
@MainActor
protocol P {}

class NonSendable {
  var state = 1
}

extension NonSendable: P {
}

```

---

<div class="post-metadata">

**Author:** ![vitamin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/vitamin/32/11098_2.png) [@vitamin](https://forums.swift.org/u/vitamin)\
**Post date:** [July 7, 2026, 5:52pm UTC](https://forums.swift.org/t/isolated-type-vs-sendable-isolated-type/88108/5 "2026-07-07T17:52:20Z")

</div>

1. Make `protocol P` inherit from `Sendable` if you want it to be sendable.
2. Even if it's sendable, `@MainActor` still ensures its properties (aka its members) are main-actor isolated.

This example should help clarify:

```swift
@MainActor
protocol P: Sendable {
    var x: Int { get set } // @MainActor applies here
}

@MainActor
class C {
    let p: any P
    let x: Int
    
    nonisolated init(p: any P) {
        self.p = p
        self.x = p.x // ❌ Main actor-isolated property 'x' 
                      // can not be referenced from a nonisolated context
    }
}

```

---

<div class="post-metadata">

**Author:** ![rayx](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/rayx/32/12204_2.png) [@rayx](https://forums.swift.org/u/rayx)\
**Post date:** [July 8, 2026, 2:30am UTC](https://forums.swift.org/t/isolated-type-vs-sendable-isolated-type/88108/6 "2026-07-08T02:30:53Z")

</div>

> [@vitamin](#):
>
> This example should help clarify:

I think errors in these examples like:

> Main actor-isolated property 'p' can not be mutated from a nonisolated context

or

> Main actor-isolated property 'x' can not be referenced from a nonisolated context

are misleading. It's possible to set property `x` in your example in a nonisolated `init`. This compiles:

```diff
  @MainActor
  protocol P: Sendable {
      var x: Int { get set } // @MainActor applies here
  }

  @MainActor
  class C {
      let p: any P
      let x: Int
    
- nonisolated init(p: any P) {
+ nonisolated init(p: any P) async {
          self.p = p
- self.x = p.x
+ self.x = await p.x
      }
  }

```

---

<div class="post-metadata">

**Author:** ![rayx](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/rayx/32/12204_2.png) [@rayx](https://forums.swift.org/u/rayx)\
**Post date:** [July 8, 2026, 2:57am UTC](https://forums.swift.org/t/isolated-type-vs-sendable-isolated-type/88108/7 "2026-07-08T02:57:48Z")

</div>

A tangentially related question (it uses a similar setup as OP's example, but not about OP's question). This doesn't compile. It's as expected because a function in another isolated domain is allowed to call this nonisolated `init`.

```swift
class NS {}

@MainActor
class C {
    let ns: NS
    
    nonisolated init(ns: NS) {
        self.ns = ns
    }
}

```

But this doesn't compile either. It that by design?

```diff
  class NS {}
  
  @MainActor
  class C {
      let ns: NS
      
- nonisolated init(ns: NS) {
+ nonisolated init(ns: sending NS) {
          self.ns = ns
      }
  }

```

~~EDIT: on a second thought, I'm not sure about the second example. Is it OK for a nonisolated _synchronous_ function to have `sending` parameters?~~

---

<div class="post-metadata">

**Author:** ![rayx](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/rayx/32/12204_2.png) [@rayx](https://forums.swift.org/u/rayx)\
**Post date:** [July 8, 2026, 3:23am UTC](https://forums.swift.org/t/isolated-type-vs-sendable-isolated-type/88108/8 "2026-07-08T03:23:12Z")

</div>

Another observation. It's well known that an existential value `any P` doesn't conform to `P`. So when I saw this code, I wasn't sure if it would compile.

```swift
protocol P: Sendable {}

@MainActor
class C {
    let p: any P
    
    nonisolated init(p: any P) {
        self.p = p
    }
}

```

It compiles. I can understand it because `Sendable` is a mark protocol. Just curious, does it mean compiler has implemented a hardcoded exception for this?

---

<div class="post-metadata">

**Author:** ![vitamin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/vitamin/32/11098_2.png) [@vitamin](https://forums.swift.org/u/vitamin)\
**Post date:** [July 8, 2026, 5:02am UTC](https://forums.swift.org/t/isolated-type-vs-sendable-isolated-type/88108/9 "2026-07-08T05:02:58Z")

</div>

Yeah it'd be helpful if the errors explained that async is not a reference.
