I have the following lines of code in practicing Combine.
import UIKit
import Combine
class ViewController: UIViewController {
// MARK: - Variables
var cancellable: AnyCancellable?
@Published var segmentNumber: Int = 0
// MARK: - IBOutlet
@IBOutlet weak var actionButton: UIButton!
// MARK: - IBAction
@IBAction func segmentChanged(_ sender: UISegmentedControl) {
segmentNumber = sender.selectedSegmentIndex
}
// MARK: - Life cycle
override func viewDidLoad() {
super.viewDidLoad()
cancellable = $segmentNumber.receive(on: DispatchQueue.main)
.assign(to: \.isEnabled, on: actionButton)
}
}
I get an error at .assign that says
Value of type 'UIView?' has no member 'isEnabled'
What am I doing wrong? Thank you.