Importing a SwiftUI View from another module results in initializer is inaccessible due to 'internal' protection level

I have declared a View called RootView inside a module called Core and marked its protection level as public. However after importing Core and attempting to use the view, I get the following error in the second image: "RootView" initializer is inaccessible due to 'internal' protection level.


EDIT: So apparently I can't upload images. I have attached image links in another post, it needs approval apparently 😀

Answered by SteveGL in 364227022

This is actually a rule in Swift. If you don't provide your own init with an explicit public modifier the generated constructor will be marked internal. This is the case even when the struct is marked public.


public struct RootView: View {

     public init() {}

     var body: some View {
          ...
     }

}
Accepted Answer

This is actually a rule in Swift. If you don't provide your own init with an explicit public modifier the generated constructor will be marked internal. This is the case even when the struct is marked public.


public struct RootView: View {

     public init() {}

     var body: some View {
          ...
     }

}

This worked, very interesting rule if you ask me 😝

Importing a SwiftUI View from another module results in initializer is inaccessible due to 'internal' protection level
 
 
Q