How to fix/suppress a MainActor-based SwiftUI concurrency warning?

I'm auditing a library for concurrency and it contains a SwiftUI view that holds an observed object (pinning it to the main actor), and conditionally conforms to DynamicViewContent, which contains a non-main actor requirement, causing the following warning:

class VM: ObservableObject {}
struct Thing<Content: View>: View {
  @ObservedObject var vm: VM
  let body: Content
}
extension Thing: DynamicViewContent where Content: DynamicViewContent {
  var data: Content.Data { self.body.data } ⚠️
}

:warning: Main actor-isolated property 'data' cannot be used to satisfy nonisolated protocol requirement

Is this a SwiftUI bug that should be fixed? Should DynamicViewContent have the same @_Concurrency.MainActor(unsafe) annotation on data?

And is there any way to silence this warning? @preconcurrency isn't helping here.

2 Likes

Even I encountered something similar Converting function value of type '@MainActor () -> ()' to '() -> Void' loses global actor 'MainActor'

I had filed a feedback for my issue, I am not sure if this is a bug either