View

open class View : IView

A Singleton IView implementation.

In PureMVC, the View class assumes these responsibilities:

  • Maintain a cache of IMediator instances.
  • Provide methods for registering, retrieving, and removing IMediators.
  • Notifiying IMediators when they are registered or removed.
  • Managing the observer lists for each INotification in the application.
  • Providing a method for attaching IObservers to an INotification‘s observer list.
  • Providing a method for broadcasting an INotification.
  • Notifying the IObservers of a given INotification when it broadcast.

@see org.puremvc.swift.patterns.mediator.Mediator Mediator

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

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

  • Constructor.

    This IView implementation is a Singleton, so you should not call the constructor directly, but instead call the static Singleton Factory method View.getInstance()

    @throws Error if Singleton instance has already been constructed

    Declaration

    Swift

    public init()
  • Initialize the Singleton View instance.

    Called automatically by the constructor, this is your opportunity to initialize the Singleton instance in your subclass without overriding the constructor.

    Declaration

    Swift

    open func initializeView()
  • View Singleton Factory method.

    Declaration

    Swift

    open class func getInstance(_ factory: () -> IView) -> IView

    Parameters

    factory

    reference that returns IView

    Return Value

    the Singleton instance of View

  • Register an IObserver to be notified of INotifications with a given name.

    Declaration

    Swift

    open func registerObserver(_ notificationName: String, observer: IObserver)

    Parameters

    notificationName

    the name of the INotifications to notify this IObserver of

    observer

    the IObserver to register

  • Notify the IObservers for a particular INotification.

    All previously attached IObservers for this INotification‘s list are notified and are passed a reference to the INotification in the order in which they were registered.

    Declaration

    Swift

    open func notifyObservers(_ notification: INotification)

    Parameters

    notification

    the INotification to notify IObservers of.

  • Remove the observer for a given notifyContext from an observer list for a given Notification name.

    Declaration

    Swift

    open func removeObserver(_ notificationName: String, notifyContext: AnyObject)

    Parameters

    notificationName

    which observer list to remove from

    notifyContext

    remove the observer with this object as its notifyContext

  • Register an IMediator instance with the View.

    Registers the IMediator so that it can be retrieved by name, and further interrogates the IMediator for its INotification interests.

    If the IMediator returns any INotification names to be notified about, an Observer is created encapsulating the IMediator instance’s handleNotification method and registering it as an Observer for all INotifications the IMediator is interested in.

    Declaration

    Swift

    open func registerMediator(_ mediator: IMediator)

    Parameters

    mediatorName

    the name to associate with this IMediator instance

    mediator

    a reference to the IMediator instance

  • Retrieve an IMediator from the View.

    Declaration

    Swift

    open func retrieveMediator(_ mediatorName: String) -> IMediator?

    Parameters

    mediatorName

    the name of the IMediator instance to retrieve.

    Return Value

    the IMediator instance previously registered with the given mediatorName.

  • Check if a Mediator is registered or not

    Declaration

    Swift

    open func hasMediator(_ mediatorName: String) -> Bool

    Parameters

    mediatorName

    Return Value

    whether a Mediator is registered with the given mediatorName.

  • Remove an IMediator from the View.

    Declaration

    Swift

    @discardableResult
    open func removeMediator(_ mediatorName: String) -> IMediator?

    Parameters

    mediatorName

    name of the IMediator instance to be removed.

    Return Value

    the IMediator that was removed from the View