Hi.
I'm studying SwiftUI, an error occurred when using .sheet in SwiftUI.
The code is:
The error is:
on line 23.
Can anyone give me some advice?
Thanks.
Addendum: Added error details and error locations.
I'm studying SwiftUI, an error occurred when using .sheet in SwiftUI.
The code is:
Code Block import SwiftUI class processStatus: ObservableObject { @Published var isRun: Bool = false } struct Home: View { @EnvironmentObject var startCollect: processStatus var body: some View { ZStack { HomeBackgound() VStack { Button(action:{ self.startCollect.isRun.toggle() }) { VStack { Text("あつめる") Text("Collect") } } .frame(width: 250, height: 250) } .sheet(isPresented: self.$startCollect.isRun) { SelectBall() .environmentObject(startCollect) } } } } struct Home_Previews: PreviewProvider { static var previews: some View { Home() .environmentObject(processStatus()) } }
The error is:
Code Block Thread 1: Fatal error: No ObservableObject of type processStatus found. A View.environmentObject(_:) for processStatus may be missing as an ancestor of this view.
on line 23.
Can anyone give me some advice?
Thanks.
Addendum: Added error details and error locations.