#3: Protocol Dispatch
Question
// Swift Quiz
— objc.io (@objcio) March 6, 2019
// by @theswiftist
protocol Drawing {
func render()
}
extension Drawing {
func circle() { print("protocol") }
func render() { circle() }
}
class SVG: Drawing {
func circle() { print("class") }
}
SVG().render()
// What's the output?
Solution
Solution: "protocol"
— objc.io (@objcio) March 7, 2019
render calls circle, which is declared in a Drawing extension.
circle is not part of Drawing’s customization points, i.e. it's not dynamically dispatched.
Thus, the circle method of SVG is not called by render.https://t.co/s7500CWmAg