Live scroll notifications from NSScrollView

Prior to OS X 10.9, observing NSScrollView scroll events involved either subscribing to bounds changes on the accompanying NSClipView or subclasses the scrollView and overriding scrollWheel(_:). In 10.9, Apple introduced responsive scrolling and a whole host of related improvements. One of those are LiveScrollNotifications. Live Scroll Events are user-initianted (via touchpad, mouse-wheel, etc) scroll events.

There are 3 available notifications:

NSScrollViewWillStartLiveScrollNotification
NSScrollViewDidLiveScrollNotification
NSScrollViewDidEndLiveScrollNotification

The major caveat that’s unfortunately not mentioned in the documentation (only in this WWDC session), is that only NSScrollViewDidLiveScrollNotification is fired universally. The start and end notifications are not triggered if scrolling with a mouse wheel for example. The upside is that there’s no subclassing or messing with unrelated views involved. Just register for the notifcation and pass the scrollView as notificationSender.

NSNotificationCenter.defaultCenter().addObserver(
    self,
    selector: #selector(scrollViewDidScroll(_:)),
    name: NSScrollViewDidLiveScrollNotification,
    object: scrollView
)