0

Im having an issue using live previews on xcode. The project builds fine and works on a simulator. I have all my environmentobjects connected so I am a bit confused. And yes I also have the EO on the app file itself.

"Cannot preview in this file - Message send failure for send display message to agent"

struct AlertSettingsView: View {
    @EnvironmentObject var avm: AlertsViewModel
    private let width: CGFloat = UIScreen.main.bounds.width
    private let height: CGFloat = UIScreen.main.bounds.height
    var body: some View {
        ZStack {
            Color.theme.orange.ignoresSafeArea()
            VStack {
                ForEach(0..<8) { text in
                    Text("lakjsdfiojas;dfkljadskl;jfj")
                }
            }
        }
        .frame(width: width, height: height/2)
        .animation(.spring())
        .cornerRadius(15)
        .offset(y: avm.settingsViewOffset) <-- commenting this line allows preview to work
    }
}
struct AlertSettingsView_Previews: PreviewProvider {
    @State static var avm = AlertsViewModel()
    static var previews: some View {
        AlertSettingsView()
            .environmentObject(avm)
            .preferredColorScheme(.dark)
    }
}
class AlertsViewModel: ObservableObject {
    @Published var showAlertsView: Bool = true
    @Published var showSettingsView: Bool = false
    @Published var settingsViewOffset: CGFloat = UIScreen.main.bounds.height/2
}
Trevor
  • 580
  • 5
  • 16
  • Works fine for me in Xcode 13. As an aside, I'd suggest that you might want to avoid the `UIScreen` method of determining dimensions and instead use the SwiftUI paradigms of `GeometryReader` if you absolutely need a dimension. – jnpdx Nov 19 '21 at 02:12
  • I now realize that it works on its own, but now how its implemented in my project. Ill be asking a new question with more code. – Trevor Nov 19 '21 at 21:44
  • @jnpdx link to new question - https://stackoverflow.com/questions/70041278/cannot-preview-this-file-message-send-failure-for-display-message-to-agent – Trevor Nov 19 '21 at 21:50

0 Answers0