Value of type 'UIView?' has no member 'isEnabled'

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.

When I try the same code, I get a different error:

Key path value type 'Bool' cannot be converted to contextual type 'Published.Publisher.Output' (aka 'Int')

If I understand your code, you try to assign segmentNumber which is Int to isEnabled which is Bool.

I guess it's a dumb question. segmentNumber is not a bool object.

What I should have done is the following.

	override func viewDidLoad() {
		super.viewDidLoad()
		
		cancellable = $segmentNumber.receive(on: DispatchQueue.main)
			.sink(receiveValue: { (number) in
				self.actionButton.isEnabled = (number == 0) ? false : true
			})
		
	}

Silly me...

Value of type 'UIView?' has no member 'isEnabled'
 
 
Q