Facade

open class Facade : IFacade

A base Multiton IFacade implementation.

@see org.puremvc.swift.core.model.Model Model

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

@see org.puremvc.swift.core.controller.Controller Controller

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

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

@see org.puremvc.swift.patterns.proxy.Proxy Proxy

@see org.puremvc.swift.patterns.command.SimpleCommand SimpleCommand

@see org.puremvc.swift.patterns.command.MacroCommand MacroCommand

  • Constructor.

    This IFacade implementation is a Singleton, so you should not call the constructor directly, but instead call the static Singleton Factory method, passing the closure that returns the IFacade implementation. Facade.getInstance() { Facade() }

    @throws Error Error if Singleton instance has already been constructed

    Declaration

    Swift

    public init()
  • Initialize the Singleton Facade instance.

    Called automatically by the constructor. Override in your subclass to do any subclass specific initializations. Be sure to call super.initializeFacade(), though.

    Declaration

    Swift

    open func initializeFacade()
  • Facade Singleton Factory method

    Declaration

    Swift

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

    Parameters

    factory

    reference that returns IFacade

    Return Value

    the Singleton instance of the IFacade

  • Initialize the Controller.

    Called by the initializeFacade method. Override this method in your subclass of Facade if one or both of the following are true:

    • You wish to initialize a different IController.
    • You have Commands to register with the Controller at startup.

    If you don’t want to initialize a different IController, call super.initializeController() at the beginning of your method, then register Commands.

    Declaration

    Swift

    open func initializeController()
  • Initialize the Model.

    Called by the initializeFacade method. Override this method in your subclass of Facade if one or both of the following are true:

    • You wish to initialize a different IModel.
    • You have Proxys to register with the Model that do not retrieve a reference to the Facade at construction time.

    If you don’t want to initialize a different IModel, call super.initializeModel() at the beginning of your method, then register Proxys.

    Note: This method is rarely overridden; in practice you are more likely to use a Command to create and register Proxys with the Model, since Proxys with mutable data will likely need to send INotifications and thus will likely want to fetch a reference to the Facade during their construction.

    Declaration

    Swift

    open func initializeModel()
  • Initialize the View.

    Called by the initializeFacade method. Override this method in your subclass of Facade if one or both of the following are true:

    • You wish to initialize a different IView.
    • You have Observers to register with the View

    If you don’t want to initialize a different IView, call super.initializeView() at the beginning of your method, then register IMediator instances.

    Note: This method is rarely overridden; in practice you are more likely to use a Command to create and register Mediators with the View, since IMediator instances will need to send INotifications and thus will likely want to fetch a reference to the Facade during their construction.

    Declaration

    Swift

    open func initializeView()
  • Register an ICommand with the Controller by Notification name.

    Declaration

    Swift

    open func registerCommand(_ notificationName: String, closure: @escaping () -> ICommand)

    Parameters

    notificationName

    the name of the INotification to associate the ICommand with

    closure

    reference that returns ICommand

  • Check if a Command is registered for a given Notification

    Declaration

    Swift

    open func hasCommand(_ notificationName: String) -> Bool

    Parameters

    notificationName

    Return Value

    whether a Command is currently registered for the given notificationName.

  • Remove a previously registered ICommand to INotification mapping from the Controller.

    Declaration

    Swift

    open func removeCommand(_ notificationName: String)

    Parameters

    notificationName

    the name of the INotification to remove the ICommand mapping for

  • Register an IProxy with the Model by name.

    Declaration

    Swift

    open func registerProxy(_ proxy: IProxy)

    Parameters

    proxyName

    the name of the IProxy.

    proxy

    the IProxy instance to be registered with the Model.

  • Retrieve an IProxy from the Model by name.

    Declaration

    Swift

    open func retrieveProxy(_ proxyName: String) -> IProxy?

    Parameters

    proxyName

    the name of the proxy to be retrieved.

    Return Value

    the IProxy instance previously registered with the given proxyName.

  • Check if a Proxy is registered

    Declaration

    Swift

    open func hasProxy(_ proxyName: String) -> Bool

    Parameters

    proxyName

    Return Value

    whether a Proxy is currently registered with the given proxyName.

  • Remove an IProxy from the Model by name.

    Declaration

    Swift

    @discardableResult
    open func removeProxy(_ proxyName: String) -> IProxy?

    Parameters

    proxyName

    the IProxy to remove from the Model.

    Return Value

    the IProxy that was removed from the Model

  • Register a IMediator with the View.

    Declaration

    Swift

    open func registerMediator(_ mediator: IMediator)

    Parameters

    mediatorName

    the name to associate with this IMediator

    mediator

    a reference to the IMediator

  • Retrieve an IMediator from the View.

    Declaration

    Swift

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

    Parameters

    mediatorName

    Return Value

    the IMediator 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 to be removed.

    Return Value

    the IMediator that was removed from the View

  • Notify Observers.

    This method is left public mostly for backward compatibility, and to allow you to send custom notification classes using the facade.

    Usually you should just call sendNotification and pass the parameters, never having to construct the notification yourself.

    Declaration

    Swift

    open func sendNotification(_ notificationName: String, body: Any? = nil, type: String? = nil)

    Parameters

    notification

    the INotification to have the View notify Observers of.

  • Create and send an INotification.

    Keeps us from having to construct new notification instances in our implementation code.

    Declaration

    Swift

    open func sendNotification(_ notificationName: String, body: Any)

    Parameters

    notificationName

    the name of the notiification to send

    body

    the body of the notification (optional)

  • Create and send an INotification.

    Keeps us from having to construct new notification instances in our implementation code.

    Declaration

    Swift

    open func sendNotification(_ notificationName: String)

    Parameters

    notificationName

    the name of the notiification to send

  • Notify Observers.

    This method is left public mostly for backward compatibility, and to allow you to send custom notification classes using the facade.

    Usually you should just call sendNotification and pass the parameters, never having to construct the notification yourself.

    Declaration

    Swift

    open func notifyObservers(_ notification: INotification)

    Parameters

    notification

    the INotification to have the View notify Observers of.