#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

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

#Preview causes concurrency error
 
 
Q