Controller
open class Controller : IController
A Singleton IController implementation.
In PureMVC, the Controller class follows the
‘Command and Controller’ strategy, and assumes these
responsibilities:
- Remembering which
ICommands are intended to handle whichINotifications. - Registering itself as an
IObserverwith theViewfor eachINotificationthat it has anICommandmapping for. - Creating a new instance of the proper
ICommandto handle a givenINotificationwhen notified by theView. - Calling the
ICommand‘sexecutemethod, passing in theINotification.
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
IControllerimplementation is a Singleton, so you should not call the constructor directly, but instead call the static Singleton Factory methodController.getInstance()@throws Error if Singleton instance has already been constructed
Declaration
Swift
public init() -
Initialize the Singleton
Controllerinstance.Called automatically by the constructor.
Note that if you are using a subclass of
Viewin your application, you should also subclassControllerand override theinitializeControllermethod 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() -
ControllerSingleton Factory method.Declaration
Swift
open class func getInstance(_ factory: () -> IController) -> IControllerParameters
factoryreference that returns
IControllerReturn Value
the Singleton instance of
Controller -
Register a particular
ICommandclass as the handler for a particularINotification.If an
ICommandhas already been registered to handleINotifications with this name, it is no longer used, the newICommandis 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
notificationNamethe name of the
INotificationfactoryreference that instantiates and returns
ICommand -
If an
ICommandhas previously been registered to handle a the givenINotification, 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) -> BoolParameters
notificationNameReturn Value
whether a Command is currently registered for the given
notificationName. -
Remove a previously registered
ICommandtoINotificationmapping.Declaration
Swift
open func removeCommand(_ notificationName: String)Parameters
notificationNamethe name of the
INotificationto remove theICommandmapping for
Controller Class Reference