#Preview causes concurrency error

I am using a preview with my view that looks like this -

#Preview {
  PaywallTwo(store: MyStore())
}

In this scenario, MyStore is a MainActor, but has an initialiser doing some async work inside a Task from the initialiser.

I am not sure if this is an implementation error, or perhaps something wrong with the new #Preview, as this was working fine with PreviewProvider

I currently have complete strict concurrency, and the error I get is: call to main actor-isolated initializer 'init()' in a synchronous nonisolated context

Post not yet marked as solved Up vote post of JosephBigBoss Down vote post of JosephBigBoss
1.4k views

Replies

Hi @JosephBigBoss, this is a known issue. You can use MainActor.assumeIsolated as a workaround, however. You can see a code example in the following post:

https://developer.apple.com/forums/thread/731320