Failed to set (titleText) user defined inspected property

169 views Asked by At

I have a UIViewController, "MainViewController"-

class MainViewController: UIViewController {
    
    @IBOutlet weak var segmentControl: UISegmentedControl!
    @IBOutlet weak var userNameTextField: UITextField!
    @IBOutlet weak var passwordTextField: UITextField!
    @IBOutlet weak var controlButton: RoundedCornerButton!
    
    override func viewDidLoad() {
        super.viewDidLoad()
       
    }
    
    @IBAction func switchBetweenSignInAndRegisterOption(_ sender: UISegmentedControl) {
        if sender.selectedSegmentIndex == 0{
            self.controlButton.text = "Sign In"
        }
        else{
            self.controlButton.text = "Register"
        }
    }
}

enter image description here

The action method- switchBetweenSignInAndRegisterOption(_:) attached to the segmentControl object and when its selectedSegmentIndex changes, the text property of my RoundedCornerButton is updated. The following is the code for RoundedCornerButton-

class RoundedCornerButton: UIButton {
 
    var text: String = "Sign In"{
        didSet{
            setNeedsLayout()
        }
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        self.layer.borderWidth = 2.0
        self.layer.cornerRadius = (self.bounds.size.width * 0.025)
        self.layer.borderColor = UIColor.green.cgColor
        self.setTitle(text, for: .normal)
        self.titleLabel?.minimumScaleFactor = 0.50
       
    }
}

It works in terms of functionality but it shows the following error in the console. I don't understand what might have gone wrong.

[ProjectName][12943:1296641] Failed to set (titleText) user defined inspected property on ([ProjectName].RoundedCornerButton): 
[<[ProjectName].RoundedCornerButton 0x7f8a13d0bd90> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key titleText.

Any help would be greatly appreciated.

1

There are 1 answers

0
Natasha On

I found the issue though I have no idea, how it stayed in my storyboard because I removed the @IBInspectable from my CustomButton's code.

When I searched and couldn't find the titleText anywhere in my code and even in the storyboard user interface, I went to the source code of my storyboard by right clicking on it and select the source code option. To my utter surprise, there was this following code snippet-

<userDefinedRuntimeAttributes>
     <userDefinedRuntimeAttribute type="string" keyPath="titleText" value="Register"/>
</userDefinedRuntimeAttributes>

Apparently even though I removed the @IBInspectable from my code, it stayed in my storyboard. I removed this part and now it works fine.