iosxcodeibinspectable

IBInspectable does not work for Int or UInt


@IBInspectable  var numLines:UInt! = 2

The above code shows a message

Failed to set (numLines) user defined inspected property

UIViewNewClass [setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key numLines.

It does work with another IBInspectable property which is UIColor.

Does IBInspectable work with Int or UInt or am I doing something wrong here or it works only with NSNumber?


Solution

  • It should work with Int, UInt, or any other numeric type. I've verified this locally with the code below:

    @IBDesignable
    class TestViewController: UIViewController {
        ...
    
        @IBInspectable var test: UInt = 0
    
        ...
    }
    

    This is showing up and working in interface builder as expected. I would make sure you have @IBDesignable on your class definition and also try doing a clean and deleting derived data.