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?
  • Flag for whether this Observer is currently registered as an observer on center.

    Declaration

    Swift

    public private(set) var observing:Bool = false
  • 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 is NSNotificationCenter.defaultCenter().

    completion

    The block to perform when name by object is observed on center.

  • Registers self to observe center for name restricted to object.

    Declaration

    Swift

    public func beginObserving()
  • Unregisters self to stop observing center for name restricted to object.

    Declaration

    Swift

    public func endObserving()