【发布时间】:2020-05-16 10:11:59
【问题描述】:
我最近将我的应用程序从 MVC 切换到 Clean Swift,但我无法决定将某些内容放在哪些类中。例如,UICollectionView/UITableView 的 delegate/datasource 函数应该放在 Interactor 还是 Presenter 中?或者可能某些函数,比如didSelectItemAt应该放在Interactor中,因为它们处理输入,而其他函数,比如cellForItemAt,应该放在Presenter中,因为它们处理视图。
在决定将某些功能放在Clean Swift 中的哪个位置时,您的决策过程是什么?`
目前我的ViewController中有以下内容
{
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool)
func scrollViewDidScroll(_ scrollView: UIScrollView)
}
以下在我的Interactor
{
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
}
以及我的Presenter中的以下内容
{
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
}
【问题讨论】:
标签: ios swift design-patterns architecture clean-architecture