I a trying to complete a simple Swift project using code only (instead of the Storyboard, but I keep getting an error message that states: “Cannot find ‘UIControlEvent’ in scope”
I’m getting this error message on the same line as my buttonInstance.addTarget code and I can’t figure out why. Could someone please help me figure out what I’m doing wrong here? Thank you.
//
// ViewController.swift
// UdacityClickCounterProject
//
// Created by I on 1/8/21.
//
import UIKit
class ViewController: UIViewController {
var count: Int = 0
var label: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
// ************* LABEL *************
let labelInstance = UILabel()
labelInstance.frame = CGRect(x: 150, y: 150, width: 60, height: 60)
labelInstance.text = "0"
view.addSubview(labelInstance)
self.label = labelInstance
// ************* BUTTON *************
let buttonInstance = UIButton()
buttonInstance.frame = CGRect(x: 150, y: 250, width: 60, height: 60)
buttonInstance.setTitle("Click Me!", for: .normal)
buttonInstance.setTitleColor(UIColor.systemPink, for: .normal)
view.addSubview(buttonInstance)
buttonInstance.addTarget(self, action: #selector(ViewController.incrementCount), for: UIControlEvent.touchUpInside)
}
@objc func incrementCount() {
self.count += 1
self.label.text = "\(self.count)"
}
}