I have a SwiftUI view:
struct CatView : View {
@State var eyesOpened: Bool = false
var body: some View {
Image(uiImage: eyesOpened ? #imageLiteral(resourceName: "OpenedEyesCat") : #imageLiteral(resourceName: "ClosedEyesCat"))
}
}
I'm trying to integrate it with in a regular UIViewController.
let hostingVC = UIHostingController<CatView>(rootView: cat)
addChild(hostingVC)
view.addSubview(hostingVC.view)
hostingVC.view.pinToBounds(of: view)
Now in the UIViewController if I try to set the eyesOpened property I get a
Thread 1: Fatal error: Accessing State<Bool> outside View.body
How are we supposed to make this work? Are SwiftUI views not supposed to work in this scenario?
OctoCatView
struct? That error is from trying to modify a@State
outside ofvar body: some View