Observer
public protocol Observer
Definition of an object for adding KVO and NSNotificationCenter
obeservations to pure Swift classes.
NSObject
s implement a method called methodSignatureForSelector:
which converts from strings to methods. Pure Swift classes do not have this method so cannot inherently perform KVO or observe NSNotificationCenter
posts. Rather than making a Swift class inherit from NSObject
, which introuduces unnecessary features, an Observer
can be retained which performs an arbitrary block on copmletion.
Two default implementations are provided, NotificationObserver
and ObjectObserver
for NSNotificationCenter
observing and keypath observing respectively.