Basics of View Controller

Architecture#

For each key function, a view controller exists. It's composed of module and view model, which are both needed to build a view and gather data from the Chat SDK. The following diagram explains the basic architecture of UIKit for iOS.

ViewController#

Every key function in Mirrorfly UIKit is available through a view controller. You can call the methods of a module and its components in the view controller to allow users to interact with the UI of the view. When events occur in the module component, the view controller is notified through a delegate. The view controller can also send data needed to update the view to the module component through a data source.

Module#

Every view controller has a corresponding module, which is composed of multiple components, also referred to as module components. The module provides these components to the view controller to compose the UI. Each view controller is set through the setupView() method of the module component. To create a view, the configure() method of the module component in the setupViews() method is called.

Component delegate#

The view controller can receive events that occur in a module component through a delegate.

Component DataSource#

A data source is used to access objects, such as data needed to update the view or implement the module component, from a view controller.

ViewModel#

A view model directly communicates with MirrorFly Chat SDK to exchange and request data. Without needing to call the Chat SDK interface, the view controller can simply use the view model to manage and process chat-related data in UIKit.

Similar to Module, Every view model also has delegates that are used to send data updates in the form of events to the view controller. The view model also uses a data source to gather necessary data from the view controller.

All view controllers provided by MirrorFly UIKit have a corresponding view model. For example, the MFUIRecentChatListViewController class that displays the channel list view owns MFUIRecentChatListViewModel.

Refer to the table below to see the corresponding view controller and view model for each key function.

Key FunctionViewControllerViewModel
Recent Chats ListMFUIRecentChatListViewControllerMFUIRecentChatListViewModel
Chat ViewMFUIChatViewParentControllerMFUIChatViewModel
ContactSync/ Create New ChatMFUICreateChatViewControllerMFUICreateChatViewModel