rspec/rules/S4186/swift/rule.adoc
2022-02-04 16:28:24 +00:00

49 lines
1.0 KiB
Plaintext

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
[source,swift]
----
@IBInspectable // Noncompliant; type is implicit
public var cornerRadius = 2.0 {
didSet {
//...
}
}
----
== Compliant Solution
[source,swift]
----
@IBInspectable
public var cornerRadius: CGFloat = 2.0 {
didSet {
//...
}
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
include::highlighting.adoc[]
endif::env-github,rspecator-view[]