mutualmobile / VIPER-SWIFT

An example Todo list app written in Swift using the VIPER architecture.
MIT License
502 stars 185 forks source link

Why don't you have weak delagates in VIPER ? #18

Open alphabikram opened 7 years ago

alphabikram commented 7 years ago

Why there are strong delegate references ?? I get my class nil when setting weak delegate . But delegate should be weak , isn't it ?

zntfdr commented 6 years ago

You're right: there are no weak references in the project. Actually there many strong reference cycles, I found a few just by looking at the AppDependencies.swift file (e.g. ListPresenter and ListWireframe reference to each other, same for ListPresenter and ListInteractor, and AddWireframe and AddPresenter).

Some of these references (most of them) are optionals, but they still are strong references.

The ideal would be to have the ListViewController to strong reference the ListPresenter, and all the other references to ListPresenter weak (from ListWireFrame, ListInteractor, and AddPresenter). Therefore when the VC is deinitialized you have a chain-reaction where every other part of the VIPER architecture for that view is deinitialized.

The problem in this project is that the ListviewController is initialized after the dependencies are already set up, therefore what I suggest above is not implementable without some code changes (that are more than just adding weak here and there).