Controller
open class Controller : IController
A Multiton 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.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
IControllerimplementation is a Multiton, so you should not call the constructor directly, but instead call the static Factory method, passing the unique key for this instanceController.getInstance( multitonKey )@throws Error if instance for this Multiton key has already been constructed
Declaration
Swift
public init(key: String) -
Initialize the Multiton
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 override public func initializeController( ) { view = MyView.getInstance(multitonKey) { MyView(key: self.multitonKey) } }Declaration
Swift
open func initializeController() -
ControllerMultiton Factory method.Declaration
Swift
open class func getInstance(_ key: String, factory: (String) -> IController) -> IControllerParameters
keymultitonKey
factoryreference that returns
IControllerReturn Value
the Multiton instance
-
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 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 -
Remove an IController instance
Declaration
Swift
open class func removeController(_ key: String)Parameters
multitonKeyof IController instance to remove
Controller Class Reference