Adding IBInspectable
to a properly-typed variable makes it available in Xcode’s Interface Builder. But that only works if variable
type is declared explicitly as one of the following:
-
Int
types, Double
, Float
, Bool
-
String
(or its optional)
-
CGFloat
, CGPoint
, CGSize
, CGRect
-
UIColor
, UIImage
(and their optionals)
-
NSString
, NSColor
, NSImage
(and their optionals)
-
NSRect
, NSPoint
, NSSize
,
Noncompliant code example
@IBInspectable // Noncompliant; type is implicit
public var cornerRadius = 2.0 {
didSet {
//...
}
}
Compliant solution
@IBInspectable
public var cornerRadius: CGFloat = 2.0 {
didSet {
//...
}
}