Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-4186

"IBInspectable" should be used correctly

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Hide
      * Remove this "IBInspectable" attribute; it should only be applied to variables.
      * Remove this "IBInspectable" attribute or use [a supported|an explicit] type.
      Show
      * Remove this "IBInspectable" attribute; it should only be applied to variables. * Remove this "IBInspectable" attribute or use [a supported|an explicit] type.
    • Highlighting:
      Hide

      IBInspectable

      Show
      IBInspectable
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Default Quality Profiles:
      Sonar way
    • Covered Languages:
      Swift
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      5min
    • Analysis Scope:
      Main Sources, Test Sources
    • SwiftLint:
      valid_ibinspectable

      Description

      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 {
           //...
        }
      }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              ann.campbell.2 Ann Campbell
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated: