FortechRomania/ios-mvp-clean-architecture

unowned references

Closed this issue · 1 comments

One suggestion for further improvement:

The weak view reference in the router can be changed to unowned.
As well as the weak view reference in the presenter.

Because the ViewController is that object which keeps the whole "module" alive both router and presenter depend on the ViewController to exist. As soon as the ViewController is deallocated both the router and presenter will be deallocated as a reaction to it. So it can never happen that the view reference turns into nil.

This saves one from all the guard statements with strange or non-existent error handling.
Also the optional calls like view?. can be removed and the code keeps concise and clear.

I'd say if you really know what you're doing then your suggestion makes sense.

However, I can see scenarios where the Presenter makes an async call, and it gets captured by the completion block (if you're not using weak/unowned self), and while this async call is in progress, the user dismisses the screen and the ViewController is deallocated. In this scenario, if on the callback, the Presenter calls a method on the View, the application will crash.

I'm fine with all micro-improvements as long we have a good understanding of what issues they might bring along.

Regards,
Cosmin