BMViewController
open class BMViewController<View> : UIViewController where View : UIView, View : BMViewWithViewControllerAndViewModel
Overview
A BMViewController
replaces the default UIViewController
. It manages a single screen,
and listen to the users interactions with it.
Refer to BMViewWithViewControllerAndViewModel to understand the architecture of a view.
The BMViewController
gives you access to a rootView
which is the view properly casted.
-
The rootView associated with the
BMViewController
.Declaration
Swift
public var rootView: View { get }
-
The latest
ViewModel
received by thisBMViewController
This should not be directly set. Please useupdate(to: View.VM)
.Declaration
Swift
public var viewModel: View.VM? { get set }
-
An more convenient initializer. Since we are not not using the storyboard
Declaration
Swift
public init()
-
Required init.
Declaration
Swift
required public init?(coder aDecoder: NSCoder)
-
Used to load the specific main view managed by this view controller.
Declaration
Swift
override public func loadView()
-
Called after the controller's view is loaded into memory.
Declaration
Swift
override open func viewDidLoad()
-
Called when view about to layout subviews.
Declaration
Swift
open override func viewWillLayoutSubviews()
-
Called everytime the VM needs to be updated. Should be called on the main Thread.
Declaration
Swift
public func update(to newModel: View.VM)
Parameters
newModel
The new
ViewModel
-
Called just before the update, override point for subclasses.
Declaration
Swift
open func willUpdate(new: View.VM?)
-
Called right after the update, override point for subclasses.
Declaration
Swift
open func didUpdate(old: View.VM?)
-
Asks to setup the interaction with the managed view, override point for subclasses.
Declaration
Swift
open func setupInteractions()
-
Adds a
BMViewController
and its root view toDeclaration
Swift
func add<V: BMViewWithViewControllerAndViewModel & UIView>( _ child: BMViewController<V>, to container: BMContainerView )
Parameters
child
The child view controller to add to the hierarchy.
container
The container in which the view of the child should go in.
-
Removes a
BMViewController
and its view from the parent view controller.Declaration
Swift
func remove()