Change this
class FilterFormViewController: UIViewController, UITextFieldDelegate {
@Binding var status: String
@Binding var type: String
@Binding var resultCount: Int
@Binding var showFilterSelectionView: Bool
init(status: Binding<String>, type: Binding<String>, resultCount: Binding<Int>, showFilterSelectionView: Binding<Bool>) {
self._status = status
self._type = type
self._resultCount = resultCount
self._showFilterSelectionView = showFilterSelectionView
super.init(nibName: nil, bundle: nil)
}
To
class FilterFormViewController: UIViewController, UITextFieldDelegate {
var status: String {
didSet {
// assign status to UIKit control
}
}
var type: String {
didSet {
// assign type to UIKit control
}
}
var resultCount: Int {
didSet {
// assign resultCount to UIKit control
submitButton.setTitle("Show \(self.resultCount) results", state: .normal)
}
}
var showFilterSelectionView: Bool
let submitButton: UIButton
init(status: String, type: String, resultCount: Int, showFilterSelectionView: Bool) {
self.status = status
self.type = type
self.resultCount = resultCount
self.showFilterSelectionView = showFilterSelectionView
super.init(nibName: nil, bundle: nil)
submitButton = UIButton()
submitButton.isEnabled = true
submitButton.addTarget(self, action: #selector(hideFilters), for: .touchUpInside)
}
You're trying to use SwiftUI patterns in UIKit, this won't work. Because the View Controller is being updated by the feedback from updateUIViewController method of the UIView Controller Representable in response to incoming changes from the view model publishers. The view model is pushing data down or over to the view controller not from view controller to view model. If you want to push data from the view controller back to the swiftui view model, you will need to delegate protocols or call back handlers so when the data changes on the UIKit side of the code the call back handlers will pass this data back to the Bindings independent of the updateUIViewController life cycle updates.