Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@IBDesignable - @IBInspectable, class not key value coding-compliant

I'm suddenly having a strange and reproducible error when using an @IBDesignable class, @IBInspectable properties are giving the following warning:

Main.storyboard: warning: IB Designables: Ignoring user defined runtime attribute for key path "test" on instance of "UIButton". Hit an exception when attempting to set its value: [ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key test.

To be clear this warning is only a problem in Xcode, it packages fine. Still annoying!

Steps to reproduce

  1. Create new project
  2. Create a custom @IBDesignable UIButton subclass, with an @IBInspectable String property:

    import UIKit
    
    @IBDesignable
    class TempButton: UIButton {
        @IBInspectable var test:String = ""
    }
    
    1. Drag a Button to a View Controller in the storyboard, and give it the custom class "TempButton" in the Identity Inspector.
    2. Now the 'Test' attribute should appear in the Attributes Inspector for 'Temp Button' properties - type anything into this field.
    3. Bam! The above warning appears. Remove the text from the field, and the warning disappears.

I've tried several solutions - different variable names, making the 'test' property an Optional, using an initializer, no luck so far.

Here is a screen capture of the problem:

enter image description here

like image 552
Craig Grummitt Avatar asked Oct 15 '15 17:10

Craig Grummitt


3 Answers

I had a similar issue but I didn't find the solution in the answers above. In my case there was an additional keyPath added by mistake in the Identity inspector:

enter image description here

like image 71
Stefo Avatar answered Oct 14 '22 14:10

Stefo


I face the same problem and I solved it. While you are open the storyboard: 1-click Editor on the upper menu. 2-click on Refresh All Views. 3-restart your application. 4-Build.

like image 32
Zaki Al Karam Avatar answered Oct 14 '22 12:10

Zaki Al Karam


I fixed this by ensuring the Interface Builder "build" did not have any errors. Here is what that means:

  1. In the left panel of Xcode, go to the Report Navigator (the last tab item at the top.)
  2. In the Reporst list, after your targets, you should see "Interface Builder". Expand that item.
  3. Ensure none of the items have errors (as designated by the red X).
  4. If you find an error here, select it and you will see more details of the problem. Fix that problem, clean, and rebuild.

Note that the issue if probably unrelated to the file you are working in. It appears that if the Interface Builder Build fails before it gets to building the file in question you will see these very cryptic warnings.

(My cause ended up being a Share Extension target referencing an AppIcon and SplashScreen asset catalog incorrectly.)

like image 21
MikecheckDev Avatar answered Oct 14 '22 12:10

MikecheckDev