[swift-users] Calling default implementation of protocol methods as selectors
Nate Birkholz
nbirkholz at gmail.com
Fri Jun 2 21:35:56 CDT 2017
protocol Foo: class {
func bar()
}
extension Foo {
func bar() {
print("bar")
}
}
class Baz: Foo {
init() {
let tapRecognizer = UITapGestureRecognizer(target: self, action:
#selector(bar))
}
}
the #selector tells me: "Argument of '#selector' refers to instance method
'bar()' that is not exposed to Objective-C" and asks me to add @objc to the
method definition.
Adding @objc to the method tells me: "@objc can only be used with members
of classes, @objc protocols, and concrete extensions of classes"
Adding @objc to the protocol doesn't fix it, just introduces new issues.
"dynamic" cannot be applied to a protocol, so cannot be used alternatively.
Is there a way to get around this? If a method is called by a gesture
recognizer, is there no way to have a default protocol implementation? I'd
like to use default implementations if possible to make my code more DRY.
Is there a roadmap/plan for swift-native selector dispatch?
Thanks. I look forward to the inevitable reply revealing the dumb thing I
missed. :)
--
Nate Birkholz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170602/d7ccd4fd/attachment.html>
More information about the swift-users
mailing list