1

I tried to make a default implementation of protocol UIScrollViewDelegate, for example:

extension UIScrollViewDelegate {
     func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
         //...
     }
}

But In a subclass UITableViewController (which conforms to UIScrollViewDelegate and) does not contain any implementation this method (neither in base class nor in subclass), this extension-provided implementation won't be called

Is there any solution to provide a default implementation for these methods?

kianoosh
  • 610
  • 6
  • 22

2 Answers2

2

Just create an extension of UIScrollView to conform to UIScrollViewDelegate protocol like this:

extension UIScrollView: UIScrollViewDelegate {
    func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
        // ...
    }
}
Lukas Würzburger
  • 6,543
  • 7
  • 41
  • 75
1

You are trying to make a Swift protocol extension on an Objective-C protocol. That's never going to work, because Objective-C cannot see a Swift protocol extension, so Cocoa (which is Objective-C) will never know about your implementation and will never call it.

matt
  • 515,959
  • 87
  • 875
  • 1,141