Search code examples
swiftinterface-builderibdesignable

UISlider - IB_DESIGNABLE - runtime attribute warning


I am trying to render a vertical slider in interface builder however, when I try to set the value interface builder gives me a warning.

What am I doing wrong here?

@IBDesignable
class VerticalSlider: UISlider {

    @IBInspectable var setOrientation: Bool! {
        didSet {

            if setOrientation == true{

                self.transform = CGAffineTransformMakeRotation(CGFloat(-M_PI_2))

            }else {

                self.transform = CGAffineTransformIdentity

            }

        }
    }


}

Solution

  • Your @IBInspectable property setOrientation shouldn't be an implicitly unwrapped optional, just a non-optional boolean property.

    If you change the declaration of setOrientation to a regular (non-optional) boolean with a default (initial) value, say false, you should no longer be prompted with warnings regarding your @IBInspectable.

    @IBInspectable var setOrientation: Bool = false { ... }