I’ve this UIViewControllerRepresentable with a @Binding which is a bool that determines if the view is in “Choice Mode” or not. I’ve a closure within the View Controller with a purpose to replace the choice mode state to false when every part is deselected. Nonetheless, I am getting the warning “Modifying state throughout view replace, this may trigger undefined habits” after I set isInSelectionMode = false
within the closure. I perceive you do not need to replace state that the View will depend on throughout rendering, however I do not see how that is doing that.
struct ExampleView: UIViewControllerRepresentable {
@Binding var isInSelectionMode: Bool
func makeUIViewController(context: Context) -> ExampleViewController {
let exampleViewController = ExampleViewController()
exampleViewController.onDeselectAll = {
isInSelectionMode = false // Warning happens right here
}
return exampleViewController
}
func updateUIViewController(_ uiViewController: StickerPickerController, context: Context) { }
}