Assume there is a protocol Draggable
, usually will be conformed by an UIView
object
protocol Draggable {
drag()
}
We can either implement drag()
in a protocol extension as option 1
// option 1
extension Draggable where Self: UIView {
func drag() {
// implementation
}
}
extension UIView: Draggable {} // added after @Rich Tolley's answer
Or we can implement drag()
in a UIView
extension as option 2
// option 2
extension UIView: Draggable {
func drag() {
// implementation
}
}
Here is my question:
- Is there a difference between these two approaches (option 1 & option 2) ?
- If yes, what's the difference and how to choose when we design a our project or library ?
And idea would be helpful.