NotificationObserver
public final class NotificationObserver:NSObject, Observer
Implementation of Observer
for observing an NSNotificationCenter
. Observation begins on init
and ends on deinit()
unless called otherwise.
For efficiency the class is marked as final. If necessary, convenience initialisers can be created using extensions.
-
The name being observed on the
center
.Declaration
Swift
public let name:String
-
The
NSNotificationCenter
to listen for notifications on.Declaration
Swift
public let center:NSNotificationCenter
-
The object to restrict observed notifications to.
Declaration
Swift
public let object:AnyObject?
-
Default initialiser.
Declaration
Swift
public init(name:String, object:AnyObject?, center:NSNotificationCenter = NSNotificationCenter.defaultCenter(), completion:(note:NSNotification) -> ())
Parameters
name
The notification name to listen for.
object
The object to restrict observed notifications from.
center
The
NSNotificationCenter
to observe. The default value isNSNotificationCenter.defaultCenter()
.completion
The block to perform when
name
byobject
is observed oncenter
.