Here's my example, let's say I have a custom UIView
with a tap gesture recognizer that responds to this function:
func handleTap(tap: UITapGestureRecognizer) {
println("Tap!")
}
I generally prefer these to be private, so I mark it as such but it doesn't work. An @objc
or dynamic
specifier is required, like so:
dynamic private func handleTap(tap: UITapGestureRecognizer) {
println("Tap!")
}
This makes me believe that public functions are dynamic by default when added to an objective-c object. Is this the case? Please cite references if found.
The Swift compiler will try to prove that a call to a method can only end up with a single implementation. If it can prove this then it will use static and not dynamic dispatch. Use of the "final" or "private" keyword, and whole module optimisation, will help with this.