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 theIFacade
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()
-
Initialize the
Controller
.Called by the
initializeFacade
method. Override this method in your subclass ofFacade
if one or both of the following are true:- You wish to initialize a different
IController
. - You have
Commands
to register with theController
at startup.
If you don’t want to initialize a different
IController
, callsuper.initializeController()
at the beginning of your method, then registerCommands
.Declaration
Swift
open func initializeController()
- You wish to initialize a different
-
Initialize the
Model
.Called by the
initializeFacade
method. Override this method in your subclass ofFacade
if one or both of the following are true:- You wish to initialize a different
IModel
. - You have
Proxy
s 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
, callsuper.initializeModel()
at the beginning of your method, then registerProxy
s.Note: This method is rarely overridden; in practice you are more likely to use a
Command
to create and registerProxy
s with theModel
, sinceProxy
s with mutable data will likely need to sendINotification
s and thus will likely want to fetch a reference to theFacade
during their construction.Declaration
Swift
open func initializeModel()
- You wish to initialize a different
-
Initialize the
View
.Called by the
initializeFacade
method. Override this method in your subclass ofFacade
if one or both of the following are true:If you don’t want to initialize a different
IView
, callsuper.initializeView()
at the beginning of your method, then registerIMediator
instances.Note: This method is rarely overridden; in practice you are more likely to use a
Command
to create and registerMediator
s with theView
, sinceIMediator
instances will need to sendINotifications
and thus will likely want to fetch a reference to theFacade
during their construction.Declaration
Swift
open func initializeView()
-
Register an
ICommand
with theController
by Notification name.Declaration
Swift
open func registerCommand(_ notificationName: String, closure: @escaping () -> ICommand)
Parameters
notificationName
the name of the
INotification
to associate theICommand
withclosure
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
toINotification
mapping from the Controller.Declaration
Swift
open func removeCommand(_ notificationName: String)
Parameters
notificationName
the name of the
INotification
to remove theICommand
mapping for -
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
. -
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
. -
Notify
Observer
s.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 theView
notifyObservers
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
Observer
s.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 theView
notifyObservers
of.