Typically, you can apply an MVM object to it in many ways. Personnaly, I recommend either a convenience initializer or a custom variable with what is called an observer of didSet values. Didset watchers invoke when their parameters are applied, without changing the stored value.
Therefore, you are given a subclass of uivew that can process your model:
class ShareUIView : UIView { var model : ShareUIModel? { didSet { guard let mode = model else { return } applyModel(mode) } } let heroImage = UIImageView() let secondHeroImage = UIImageView() let longHeroLabel = UILabel() let shortHeroLabel = UILabel()
So, you can either apply it to your UIViewController view by initializing it:
class Controller : UIViewController { override func viewDidLoad() { super.viewDidLoad() let shareview = ShareUIView(model: ShareUIModel.testObject()) view.addSubview(shareview) shareview.frame =
This method means you need to set the size afterwards.
Or you can first create a ShareView, and then apply the model object (for example, from a custom selection or from a network task) by applying the model to the ShareView model ShareView . This requires that you have a strong reference to it, as when initializing it in your Controller class:
class Controller : UIViewController { var shareView : ShareUIView = {
From this, you should have enough examples to get creative with how to update the MVVM view with its contents of the model object. Then you also created methods to clear the content, reject it, etc., depending on the use case of the view itself.
source share