You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If this is a new rule request, please ignore all sections below this one, format
this issue's title as Rule Request: [Rule Name] and describe:
Describe:
#selector() doesn't warn you if you reference method from different class. In class A you could be adding target to button button.addTarget(self, action: #selector(B.didTap), for: .touchUpInside) and as long as B.didTap is accessible this code compiles but on tap of the button crashes the app. I would keep this rule simple and it would only check for existence of method in case target is being added to self.
Why should this rule be added? Share links to existing discussion about what
the community thinks about this.
I don't have link to an existing discussion.
Provide several examples of what would and wouldn't trigger violations.
What would trigger:
final class A: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let button = UIButton()
button.addTarget(self,
action: #selector(B.didTap),
for: .touchUpInside)
}
}
what wouldn't trigger:
final class A: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let button = UIButton()
button.addTarget(self,
action: #selector(A.didTap),
for: .touchUpInside)
}
}
Should the rule be configurable, if so what parameters should be configurable?
This rule should not be configurable.
Should the rule be opt-in or enabled by default? Why?
See README.md for guidelines on when to mark a
rule as opt-in.
I believe this rule should be enabled by default.
The text was updated successfully, but these errors were encountered:
@marcelofabri you are right, it should work with any class that uses target-action.
However I realised one problem with implementation, what if the method in action is in subclass? That way the method is invisible to SwiftLint but won't crash the application. Is there a way to work around this?
New Issue Checklist
Rule Request
If this is a new rule request, please ignore all sections below this one, format
this issue's title as
Rule Request: [Rule Name]
and describe:Describe:
#selector() doesn't warn you if you reference method from different class. In class A you could be adding target to button
button.addTarget(self, action: #selector(B.didTap), for: .touchUpInside)
and as long asB.didTap
is accessible this code compiles but on tap of the button crashes the app. I would keep this rule simple and it would only check for existence of method in case target is being added toself
.the community thinks about this.
I don't have link to an existing discussion.
What would trigger:
what wouldn't trigger:
This rule should not be configurable.
See README.md for guidelines on when to mark a
rule as opt-in.
I believe this rule should be enabled by default.
The text was updated successfully, but these errors were encountered: