I'm using Xcode 11 to test swiftUI but I can't manage to get my Content_Previews working. My code is similar to the introductory talk given by Apple.
Since I don't have MacOS Catalina, I'm testing this with the Simulator and with real device. I can't manage to see the DEBUG Preview with my testData.
The ContentView.swift looks like:
import SwiftUI
struct ContentView: View {
var devices: [Device] = []
var body: some View {
NavigationView {
List(devices) { device in
Image(systemName: "gamecontroller")
VStack() {
Text(device.name)
if(device.isConnected){
Text("Connected").font(.subheadline).foregroundColor(.secondary)
}else{
Text("Not Connected").font(.subheadline).foregroundColor(.secondary)
}
}
}
.navigationBarTitle(Text("Devices"))
}
}
}
#if DEBUG
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView(devices: testData)
}
}
#endif
Then, the Device struct is the following:
import SwiftUI
struct Device : Identifiable {
var id = UUID()
var name: String
var isConnected: Bool = false
}
let testData = [
Device(name: "devA"),
Device(name: "devB"),
Device(name: "devC")
]
Somehow, the ContentView_Previews is not executed, even though, DEBUG is on. (I tested this putting a conditional Text View). Any idea of what is going wrong? My guess is that the PreviewProvider ContentView_Previews
is not being called and that I'm missing some configuration.