@objc
is redundant when used with implicit Objective-C attribute SW-R1011The @objc
attribute is used to expose Swift declarations to Objective-C code.
However, it can be redundant in some cases, where the declaration is already
implicitly @objc
, or it's not necessary for the declaration to be exposed to
Objective-C code.
Having a redundant @objc
attribute adds unnecessary overhead to the code, and
can make it harder to read and maintain. It's important to avoid using
redundant @objc
attributes, especially in performance-critical code.
In summary, it's important to avoid using redundant @objc
attributes as they
add unnecessary overhead to the code and can make it harder to read and
maintain.
Here are some examples of redundant @objc
attribute usage:
@objc @IBInspectable private var foo: String? {}
@objcMembers
class Foo: NSObject {
@objc var bar: Any?
@objc var foo: Any?
@objc
class Bar {
@objc
var foo: Any?
}
}
@objc private var foo: String? {}
@objcMembers
class Foo {
var bar: Any?
@objc
class Bar: NSObject {
@objc
var foo: Any?
}
}