Hello, I am trying to code a SwiftUI view in a custom framework.
The reason to do this is that I want to hide sub-views' implementation, since Swift does not provide a namespace. So, I made a sub-framework and Implemented a test view inside of that.
But, inside the Framework(named Calendar
), If I write these code, then I cannot see the preview. Of course I can preview outside of the Framework, for example, when I import & use this in some single-view app.
import SwiftUI
public struct Cell: View {
public init() {}
public var body: some View {
Text("CELL for SingleView")
}
}
struct Cell_Previews: PreviewProvider {
init() {}
static var previews: some View {
Cell()
}
}
Everything works good, but there is an error from the preview pane:
Compiling failed: 'Cell_Previews' is not a member type of 'Calendar'
I tried to wrap the struct with #if DEBUG
then:
import SwiftUI
public struct Cell: View {
public init() {}
public var body: some View {
Text("CELL for SingleView")
}
}
#if DEBUG
struct Cell_Previews: PreviewProvider {
init() {}
static var previews: some View {
Cell()
}
}
#endif
The error is changed! into:
Compiling failed: 'Cell' is not a member type of 'Calendar'
So I wrapped both of structs:
import SwiftUI
#if DEBUG
public struct Cell: View {
public init() {}
public var body: some View {
Text("CELL for SingleView")
}
}
struct Cell_Previews: PreviewProvider {
init() {}
static var previews: some View {
Cell()
}
}
#endif
The preview worked like a magic! But obviously, it is a crazy idea since it does not work in release mode.
I suspect that this is a bug. What should I do?