首页 > 解决方案 > 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!

标签: swiftarchitecture

解决方案


在 iOS 中使用委托是首选方式,因为它允许您保持代码组件解耦。当前视图控制器不应该真正关心谁是它的委托人,无论它是另一个视图控制器还是某个协调器。

回顾一下:

  • 要向前传递数据,请使用依赖注入
  • 要向后传递数据,请使用委托

对于向后传递数据,我们也可以使用闭包属性,但我个人并不喜欢这样做。


推荐阅读