Với mô hình VIPER, chúng ta tham khảo kiến trúc như sau
viper
Một số lưu ý trong cây thư mục của module mà chúng ta đang phát triển:
+ View ( ViewController , extension Protocol ) : chứa X_ViewController và X_ViewControllerProtocol
X_ViewController
Biến:
var presenter : X_PresenterProtocol
func showView ( ví dụ viewDidLoad() )
Trong func viewDidLoad(), chúng ta phải làm 1 số việc cơ bản sau
Gọi tới X_WireFrame :: Tiến hành khởi tạo dữ liệu -> chỗ này sai rồi nhé, View không tương tác với WireFrame
Khởi tạo dữ liệu
Khởi taọ presenter và thực hiện presenter.viewDidLoad()
presenter được khởi tạo thế nào vậy???

X_ViewControllerProtocol
var presenter : PresenterProtocol? {get set}
func : showView

+ Presenter ( NSObject + Protocol ) : đây là phần code nặng nhất và là phần lõi chính trong module , và là khu vực điều hướng chính , gồm Presenter và PresenterProtocol
Presenter
Biến:
var view : ViewProtocol
var wireFrame : WireFrameProtocol
var interactor : InteractorProtocol
func viewDidLoad
func loadItems
func showSelectedItem

PresenterProtocol : có đầy đủ các hàm
var view : ViewProtocol? {get set}
var wireFrame : WireFrameProtocol? {get set}
var interactor : InteractorProtocol? {get set}
func viewDidLoad
func loadItems
func showSelectedItem

+ Interactor ( X_InputProtocol ) : đây là phần kết nối giữa Presenter và Entity (model) , gồm Interactor và InteractorInputProtocol và InteractorOutputProtocol
File Interactor
Biến:
var presenter : PresenterProtocol
func loadItems
func

File InteractorProtocol ( chú ý là sẽ gồm InteractorInputProtocol và InteractorOutputProtocol )
X_InteractorInputProtocol
var presenter : DishListInteractorOutputProtocol? {get set}

X_InteractorOutputProtocol

+ Entity : model
File Model: NSObject v.v tuỳ tình hình

+ Router : phần điều hướng, được viết WireFrame
File WireFrame
let presenter = Presenter()
let interactor = Interactor()
let wireFrame = WireFrame()
let localDataManager = LocalDataManager()
let remoteDataManager = RemoteDataMangager()
và chúng ta tiến hành set rất nhiều thứ trong này gần như đẻ khởi tạo biến
func showDetail1 , showDetail2 , static func createPromotionDetailViewController, hoặc class func createPostListModule() -> UIViewController , hoặc class func createListFoodModule(foodListref: ListFoodView)

File WireFrameProtocol
var presenter : PresenterProtocol? {get set}

Chúng ta sử dụng nguồn bài viết ở đây làm hướng dẫn chính nhé
https://medium.com/swift-india/viper-architecture-example-in-ios-in-swift-4-6f656a441f7c
https://github.com/GABHISEKBUNTY/Viper-Architecture
và áp dụng vào dự án đang triển khai để nắm tình hình thực tế

Bài viết khác

How to create your own install-on-air service for installing ios application

To upload your IPA file to your own server, you can follow these steps: Create a web server: You’ll need a web server to host your IPA file. You can either set up a physical server or use a cloud-based server provider such as Amazon Web Services (AWS) or Google Cloud Platform (GCP). Upload the […]

RxSwift for ios and swift developer

RxSwift is a powerful tool for iOS and Swift developers that allows you to write cleaner and more maintainable code by leveraging the power of reactive programming. In this article, we will take a look at what reactive programming is, and how you can get started with using RxSwift in your own projects. What is […]

Basic concepts of Protocol-Oriented Programming (POP) in swift and ios developer

Protocol-Oriented Programming (POP) is a programming paradigm introduced in Swift that emphasizes the use of protocols as a way to define and enforce common behavior for multiple types. POP is a powerful tool for designing and organizing code, and can be used to achieve many of the same goals as object-oriented programming, but with greater […]

Basic concepts of Object-Oriented Design (OOD)

Object-Oriented Design (OOD) is a software design paradigm that emphasizes the use of objects and classes to represent real-world entities and their behavior. OOD is based on the idea that software systems can be modeled as a collection of objects that interact with each other to achieve a common goal. The following are some of […]

iOS Clean Architecture with MVC

iOS Clean Architecture with MVP