I am trying to implement a checkbox in Swift. I used the answer of an other post to get started. First I created a button in the storyboard and gave it the class checkbox. After that I, created the class checkbox. It is currently looking like that. I had do make some adjustments from the other post, because he was using a different version of swift.
class checkbox: UIButton {
//Images
let checkedImage = UIImage(named: "selected")! as UIImage
let uncheckedImage = UIImage(named: "rectangle")! as UIImage
// Bool property
var isChecked: Bool = false {
didSet{
if isChecked == true {
self.setImage(checkedImage, for: .normal)
} else {
self.setImage(uncheckedImage, for: .normal)
}
}
}
func buttonClicked(sender: UIButton) {
if (sender == self) {
if self.isChecked == true
{
self.isChecked = false
}
else
{
self.isChecked = true
}
}
}
override func awakeFromNib() {
self.addTarget(self, action: Selector(("buttonClicked:")),for:UIControlEvents.touchUpInside)
self.isChecked = false
}
}
But now, I always get the following error in the AppDelegate, when I click the checkbox.
terminating with uncaught exception of type NSException