# \[Pitch\] Unsafe Assume on MainActor

**URL:** <https://forums.swift.org/t/pitch-unsafe-assume-on-mainactor/63074>\
**Category:** Pitches\
**Created:** [February 11, 2023, 5:12am UTC](https://forums.swift.org/t/pitch-unsafe-assume-on-mainactor/63074 "2023-02-11T05:12:35Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![kavon](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/kavon/32/9774_2.png) [@kavon](https://forums.swift.org/u/kavon)\
**Post date:** [February 14, 2023, 7:50am UTC](https://forums.swift.org/t/pitch-unsafe-assume-on-mainactor/63074/15 "2023-02-14T07:50:40Z")

</div>

> [@kabiroberai](#):
>
> FYI I believe you can already do something quite similar using `@MainActor(unsafe)`; in fact the proposed `unsafeAssumeOnMainActor` function can be written in terms of that

Thanks for pointing this out. The unsafe variant of `MainActor` checks the context in which the function is called. It will emit an error if the context has adopted any concurrency features (e.g., the call is in an `actor` method), or if compiled with `-strict-concurrency=complete`. That mode is suppose to be a preview of Swift 6, so as a long-term adoption tool I don't know if it will hold-up.

That's one of the downsides of trying to use `@MainActor(unsafe)` for this: the dependence on the strictness of concurrency checking. The other downside is that it doesn't do any runtime check that you are on the right actor. If you remembered to compile with `-enable-actor-data-race-checks` when using `@MainActor(unsafe)` then you will the check, and then you'll have a pretty close approximation of this `unsafeAssumeMainActor`.

> [@kabiroberai](#):
>
> Would love to see this pitch tweaked to focus on better usability + discoverability for the existing attribute instead — for example afaik the attribute only works on functions right now, not closures

Yea seems like a bug that `@MainActor(unsafe)` closures get treated like `@MainActor`, even with `-strict-concurrency=minimal`.

---

_[View the full topic](https://forums.swift.org/t/pitch-unsafe-assume-on-mainactor/63074)._
