I have some protocol:
@objc protocol SomeProtocol { }
that I extend for UIViewController
instances. In this extension I want to create and add a button, whose selector is also defined in the protocol:
extension SomeProtocol where Self: UIViewController {
func addSomeButton() {
let someButton = UIButton()
someButton.addTarget(self, #selector(someButtonPressed), for: .touchUpInside)
view.addSubview(someButton)
}
@objc func someButtonPressed() {
}
}
However, I get the error @objc can only be used with members of classes, @objc protocols, and concrete extensions of classes at the definition of someButtonPressed
.
Is there any way to achieve this using protocols?
Thanks in advance for any suggestions!