I have implemented the .OnReceive method in a SwiftUI view to be able to keep track of some variebles.
But as you can see I have all the .onReceive's code is commented and the reason is that if I don't I get the following error on the canvas:
This is my ContentView_Previews Struct:
Could anyone help me to understand the error? I suspect that the ContentView_Previews Struct need some extra value to be able to interpret the view on the canvas.
Thanks for the help!
This error means that the preview cannot render, and the reason for that is that it doesn't have the @EnvironmentObject var appState: States
that your LoginView
uses in the .onReceive
.
So, you need to set it:
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
LoginView()
.previewLayout(.device)
.environmentObject(States()) // here
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.