This code:
@MainActor
import SwiftUI
@MainActor
func renderImage(_ view: some View) -> CGImage? {
let renderer = ImageRenderer(content: view)
return renderer.cgImage
}
let image = renderImage(
ZStack {
Image(systemName: "drop.fill").foregroundStyle(.white)
Image(systemName: "drop").foregroundStyle(.black)
}.font(.system(size: 30))
)
Compiles but shows warning:
Conformance of underlying type of 'some View' to protocol 'View' may be isolated and cannot be passed to main actor-isolated context
Xcode 27.0 beta 4
Swift Concurrency Checking: Complete
Approachable Concurrency: No
Default Actor Isolation: nonisolated
If I understand correctly:
The issue seems to be that .font() returns an opaque type "some View".
And "some View" may also conform to View only constrained to some actor.
(as in "struct A: @someGlobalActor View").
But renderImage() is @MainActor, and thus the view it is passed, needs to conform to View from the main actor. renderImage() needs to be @MainActor, because ImageRenderer.init() is @MainActor.
Is there any way to fix this warning?