Failed to set () user-defined validation property (UIButton)

In a simple ViewController, I added one UIButton. I would like to use Custom Runtime Attributes. At the moment, I have added the default Bool attribute.

screen

The button is @IBOutlet:

@IBOutlet var button:UIButton!

The link in the storyboard is complete.

I have nothing else in my application.

I got this error:

2017-03-26 20:31:44.935319+0200 ISAMG[357:47616] Failed to set (keyPath) user defined inspected property on (UIButton): 
[<UIButton 0x15e3a780> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key keyPath.

I don’t understand what I am missing.

EDIT 1

Following @timaktimak's advice, I created a custom UIButton class:

@IBDesignable
class ChoiceButton: UIButton {

    @IBInspectable var keyPath: Bool! {
        didSet {
            print("didSet viewLabel, viewLabel = \(self.keyPath)")
        }
    }

    required init(coder aDecoder: NSCoder)  {
        super.init(coder: aDecoder)!
    }
}

screen2

The error is the same:

2017-03-26 22:32:27.389126+0200 ISAMG[429:71565] Failed to set (keyPath) user defined inspected property on (ISAMG.ChoiceButton): 
[<ISAMG.ChoiceButton 0x14e8f040> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key keyPath.
+6
source share
3 answers

Well, your button does not have a property called keyPathto set it to something.

Runtime , .

, UIButton, backgroundColor:

enter image description here

UIButton, , " ".

, , , : fooobar.com/questions/381539/...

: , ( ) , Runtime User Defined Runtime ( , Interface Builder , ).

,

var keyPath: Bool!

var keyPath: Bool = false

constuctor. - String ( String), Bool. Runtime User Defined Runtime, !

, ! !

+25

layer.cornerRadius cornerRadius.

+1

5 , . , , , Interface Builder IBInspectable, .

Int, type , 3 . , . , .

, Identity Inspector , , :

enter image description here

.

0

Source: https://habr.com/ru/post/1673243/


All Articles