Giuma is correct -- if syntactically correct code compiles and runs on the device or Simulator, then the failure of Preview is a bug, period. I can reproduce the problem in ten lines of code (not counting closing braces):
struct Outer {
static let hello = "Hello"
// Move MyText here and Preview compiles and runs.
}
extension Outer {
// With MyText here app compiles and runs correctly but
// Preview fails with "Compiling failed: cannot find 'hello' in scope"
struct MyText: View {
var body: some View {
Text(hello)
// This does work with Preview: Text(Outer.hello)
}
}
}
struct ContentView: View {
var body: some View {
Outer.MyText()
}
}
#Preview {
ContentView()
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: