swift 架构_在Swift 5中实现干净的VIP架构

swift 架构In this article, we’ll learn how to implement a Clean VIP architecture in Swift. We’ll do so by creating a Core Data powered app that saves, deletes, and displays items in a UITableView. It al...
摘要由CSDN通过智能技术生成

swift 架构

In this article, we’ll learn how to implement a Clean VIP architecture in Swift. We’ll do so by creating a Core Data powered app that saves, deletes, and displays items in a UITableView. It also has a details page to illustrate how we navigate and pass data between modules.

在本文中,我们将学习如何在Swift中实现Clean VIP架构。 为此,我们将创建一个支持Core Data的应用程序,该应用程序可以保存,删除和显示UITableView项目。 它还有一个详细信息页面,以说明我们如何在模块之间导航和传递数据。

The VIP pattern was created to address some issues of the VIPER architecture. One problem was that the Presenter (P) component may become too large — as it’s responsible for handling UI actions and preparing data for the view. To facilitate the single responsibility principle the relationship between objects was altered. While the VIPER’s V part means both ViewController and a UIView, the VIP’s “V” means simply ViewController. Therefore, the UIView is a separate component now, which makes view controllers a little bit thinner.

创建VIP模式是为了解决VIPER体系结构的某些问题。 一个问题是Presenter ( P )组件可能会变得太大-因为它负责处理UI动作并为视图准备数据。 为了促进单一责任原则,更改了对象之间的关系。 VIPER的V部分同时表示ViewControllerUIView ,而VIP的“ V ”仅表示ViewController 。 因此, UIView现在是一个单独的组件,这使视图控制器更薄一些。

Before we start, let’s understand the terminology behind the VIP pattern. Each module or scene usually involves the following components with their corresponding responsibilities:

在开始之前,让我们了解VIP模式背后的术语。 每个模块或场景通常包含以下组件,并具有相应的职责:

  • View: Anything that is a UIView subclass. It should be reusable and as passive as possible.

    View 任何属于UIView子类的东西。 它应该是可重用的并且尽可能被动。

  • ViewController: An object that is created to manage the behavior of a specific view. May act as a data source or event handler. Calls necessary Interactor’s methods in response to view events and receives raw view-representable data from the Presenter.

    ViewController 创建用于管理特定视图行为的对象。 可以充当数据源或事件处理程序。 调用必要的Interactor方法以响应视图事件,并从Presenter接收可表示视图的原始数据。

  • Interactor: Performs business logic in the app, but is not aware of lower-level implementations, such as network clients or databases. For this, we have dependencies on services that do know about them and use them directly. When a service’s task is performed, the Interactor obtains the result and sends it to the Presenter.

    Interactor :在应用程序中执行业务逻辑,但不了解较低级别的实现,例如网络客户端或数据库。 为此,我们依赖确实知道它们并直接使用它们的服务。 执行服务的任务时, Interactor获取结果并将其发送给Presenter

  • Presenter: Receives a task’s result from the interactor and transforms it into a view-suitable format. For example, it may transform an array of complicated Core Data objects into a simple array of Strings

    Presenter :从交互器接收任务的结果,并将其转换为适合视图的格式。 例如,它可以将复杂的Core Data对象数组转换为String的简单数组。

  • Router: Responsible for performing navigation inside the app. Typically has a dependency on a UINavigationController that’s provided by a Configurator .

    Router :负责在应用内执行导航。 通常依赖于Configurator提供的UINavigationController

  • Configurator: An object that creates a module by linking all the previous components.

    Configurator :通过链接所有先前的组件来创建模块的对象。

  • Entity: A plain object, such as a Core Data entity or a Codable model.

    Entity :普通对象,例如核心数据实体或可Codable模型。

Take a look at this diagram (an object that’s being pointed to is owned by the pointing object):

看一下此图(指向的对象归指向对象所有):

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值