Observer

open class Observer : IObserver

A base IObserver implementation.

An Observer is an object that encapsulates information about an interested object with a method that should be called when a particular INotification is broadcast.

In PureMVC, the Observer class assumes these responsibilities:

  • Encapsulate the notification (callback) method of the interested object.
  • Encapsulate the notification context (this) of the interested object.
  • Provide methods for setting the notification method and context.
  • Provide a method for notifying the interested object.

@see org.puremvc.swift.core.view.View View

@see org.puremvc.swift.patterns.observer.Notification Notification

  • Declaration

    Swift

    public var notifyMethod: ((_ notification: INotification) -> ())?
  • Declaration

    Swift

    weak public var notifyContext: AnyObject?
  • Constructor.

    The notification method on the interested object should take one parameter of type INotification

    Declaration

    Swift

    public init(notifyMethod: ((INotification) -> ())?, notifyContext: AnyObject?)

    Parameters

    notifyMethod

    the notification method of the interested object

    notifyContext

    the notification context of the interested object

  • Notify the interested object.

    Declaration

    Swift

    open func notifyObserver(_ notification: INotification)

    Parameters

    notification

    the INotification to pass to the interested object’s notification method.

  • Compare an object to the notification context.

    Declaration

    Swift

    open func compareNotifyContext(_ object: AnyObject) -> Bool

    Parameters

    object

    the object to compare

    Return Value

    boolean indicating if the object and the notification context are the same