SwiftUI Preview fails in module named "View"

Using Xcode 12 Beta 2.

Interesting find : just added my first SwiftUI view (File > New > File... > SwiftUI View) in my existing project, which is heavily UIKit based (hoping to slowly migrate).

Note : that file was added to a module / framework named "View" (for historical reasons).

The new file comes with the following template code :

Code Block
import SwiftUI
struct MemberView: View {
    var body: some View {
        Text("Hello, World!").font(.title)
    }
}
struct MemberView_Previews: PreviewProvider {
    static var previews: some View {
        MemberView()
    }    
}


However when I click on "Resume" in the Canvas to see the Preview, I get the following error after a little while (and yes, the build succeeds and I can run the app on a device or simulator) :

Failed to build MemberView.swift. Compiling failed : 'MemberView_Previews' is not a member type of 'View'

The exact same code was created in another SwiftUI view template, but this time in a different module (one named "Model") and that works ok (i.e. I can see the Preview). Same experiment was done for the "root" of the Project and that works as well.

Is there any reason why there would be a naming conflict between a module called "View" and the actual View protocol ? Seems surprising to me...

See the "Diagnostic" attachment for more info.




Accepted Reply

Thanks for the response.
Unfortunately, it doesn't : "Compiling failed : circular reference".

I even tried to replace all the 'View' references with 'SwiftUI.View', but that brought me back to the previous error.
I guess I am gonna have to rename my module... Luckily that's something I can control.

Replies

This is a known issue. You could try adding a typealias View = SwiftUI.View to the top of the file: does that fix the problem?
Thanks for the response.
Unfortunately, it doesn't : "Compiling failed : circular reference".

I even tried to replace all the 'View' references with 'SwiftUI.View', but that brought me back to the previous error.
I guess I am gonna have to rename my module... Luckily that's something I can control.