Controller

open class Controller : IController

A Multiton 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.multicore.core.View View

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

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

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

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

  • Constructor.

    This IController implementation is a Multiton, so you should not call the constructor directly, but instead call the static Factory method, passing the unique key for this instance Controller.getInstance( multitonKey )

    @throws Error if instance for this Multiton key has already been constructed

    Declaration

    Swift

    public init(key: String)
  • Initialize the Multiton 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
    override public func initializeController(  ) {
        view = MyView.getInstance(multitonKey) { MyView(key: self.multitonKey) }
    }
    

    Declaration

    Swift

    open func initializeController()
  • Controller Multiton Factory method.

    Declaration

    Swift

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

    Parameters

    key

    multitonKey

    factory

    reference that returns IController

    Return Value

    the Multiton instance

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

  • Remove an IController instance

    Declaration

    Swift

    open class func removeController(_ key: String)

    Parameters

    multitonKey

    of IController instance to remove