Controller

open class Controller : IController

A Singleton IController implementation.

In PureMVC, the Controller class follows the ‘Command and Controller’ strategy, and assumes these responsibilities:

Your application must register ICommands with the Controller.

The simplest way is to subclass Facade, and use its initializeController method to add your registrations.

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

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

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

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

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

  • Constructor.

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

    @throws Error if Singleton instance has already been constructed

    Declaration

    Swift

    public init()
  • Initialize the Singleton Controller instance.

    Called automatically by the constructor.

    Note that if you are using a subclass of View in your application, you should also subclass Controller and override the initializeController method in the following way:

    // ensure that the Controller is talking to my IView implementation
    public func initializeController() {
        view = MyView.getInstance { MyView() }
    }
    

    Declaration

    Swift

    open func initializeController()
  • Controller Singleton Factory method.

    Declaration

    Swift

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

    Parameters

    factory

    reference that returns IController

    Return Value

    the Singleton instance of Controller

  • Register a particular ICommand class as the handler for a particular INotification.

    If an ICommand has already been registered to handle INotifications with this name, it is no longer used, the new ICommand is used instead.

    The Observer for the new ICommand is only created if this the first time an ICommand has been regisered for this Notification name.

    Declaration

    Swift

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

    Parameters

    notificationName

    the name of the INotification

    factory

    reference that instantiates and returns ICommand

  • If an ICommand has previously been registered to handle a the given INotification, then it is executed.

    Declaration

    Swift

    open func executeCommand(_ notification: INotification)

    Parameters

    note
  • 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.

    Declaration

    Swift

    open func removeCommand(_ notificationName: String)

    Parameters

    notificationName

    the name of the INotification to remove the ICommand mapping for