swift - Should I use Delegation or DataStore to passing data BACKWARD in Clean Swift architecture?
问题描述
Now i'm trying to learn about Clean Swift architecture.
I'm using DataStore
to passing data to next viewController
and calling backward-viewController's interactor
to do something when I want to send data backward like delegation
.
I don't sure that this is suit with architecture. Please show me how.
I know that it is good to use DataStore
for passing data FORWARD to next viewController
. But is it good to use DataStore
for passing data BACKWARD?
As all of my tableViewCells
, collectionViewCells
, etc. using delegation
to sending any actions or datas to it's viewController
, Will it be good and less confusing to use delegation
for sending data BACKWARD too?
Thanks!
解决方案
在 iOS 中使用委托是首选方式,因为它允许您保持代码组件解耦。当前视图控制器不应该真正关心谁是它的委托人,无论它是另一个视图控制器还是某个协调器。
回顾一下:
- 要向前传递数据,请使用依赖注入
- 要向后传递数据,请使用委托
对于向后传递数据,我们也可以使用闭包属性,但我个人并不喜欢这样做。
推荐阅读
- php - 我在将数据从 PHP 更新到我的 SQL 数据库时发现了一个问题,我想根据学生 ID 进行更新
- ajax - 重新加载页面后 Ajax 查询不起作用
- php - 在 Woocommerce 中添加产品属性列以编辑订单页面
- html - 网页抓取 excel VBA
- php - 嗨,我想使用电报机器人从电报表中读取参数并将其发送给用户,但我的请求失败
- php - 无法在 packagist 搜索并需要私有作曲家包
- javascript - 从方法中的回调获取主类(NODEJS)
- python - Python:(Pandas)如何忽略按 id 分组的最低和最高 25% 的值以进行均值计算
- ssl - 我遇到此错误:站点缺少有效的受信任证书(net::ERR_CERT_AUTHORITY_INVALID)
- c# - 我正在使用 c# DateTime,我需要以 24 小时格式获取 .Hour 属性