Infinum iOS Talks #2 - VIPER for everybody by Damjan Vujaklija

Preview:

Citation preview

VIPER for everybody

DAMJAN VUJAKLIJA DAMJAN.VUJAKLIJA@INFINUM.CO, @DAMJANVUJAKLIJA

00CHALLENGES

CAN WE FIND AN ARCHITECTURE THAT IS:

• maintanable and testable

• handles Apple’s MVC problem

• can be adopted by our entire iOS team

• plays well with Swift

MVC

MVC BY APPLE

MVP

MVVM

VIPER

01VIPER COMPONENTS

VIPER

• Router, Entity, Presenter, Interactor, View

• good separation of concerns

• responsibilities can be grouped into two categories: when to

do something and how to do something

WIREFRAME (ROUTER)

WIREFRAME (ROUTER)

• knows how to navigate

WIREFRAME (ROUTER)

• knows how to navigate

• knows how to setup module components

PRESENTER

PRESENTER

• knows when to navigate

PRESENTER

• knows when to navigate

• knows when to fetch data

PRESENTER

• knows when to navigate

• knows when to fetch data

• knows when to present data

VIEW

VIEW

• knows how to present data

VIEW

• knows how to present data

• knows how to delegate user interactions

INTERACTOR

INTERACTOR

• knows how to fetch and prepare data

ENTITY

• knows how to hold data (actually is data)

WHEN AND HOW RESPONSIBILITIES

• roughly put, when is the gist of the application business logic, and how is

most often implementation details

WHEN AND HOW RESPONSIBILITIES

• roughly put, when is the gist of the application business logic, and how is

most often implementation details

• this means presenters define most of your apps behaviour

WHEN AND HOW RESPONSIBILITIES

• roughly put, when is the gist of the application business logic, and how is

most often implementation details

• this means presenters define most of your apps behaviour

• interactos define business data logic (enterprise business logic)

02TAILORING VIPER

CLEANLINESS IS NEXT TO GODLINESS…

…A LITTLE DIRT GOES A LONG WAY.

MODULE LIFECYCLE

• wireframe → presenter →view

• view → presenter → wireframe

THE ‘I’ IN VIPER IS COOL AND ALL, BUT…

• ditch the interactors if they’re giving you too much trouble

and communicate directlly with an APIHandler/services/…

• work with instances and not classes for networking to ease

mocking

03COMMUNICATION

WIREFRAME & PRESENTER

PRESENTER & VIEW

PRESENTER & INTERACTOR

04TOOLS

TOOLS

• project generator

• module generator

VEKI SAYS: “YOU’RE WELCOME.”

05ISSUES

• method proxying

• data passing between modules

• storyboards

• child view controllers

COMMON ISSUES

THINGS THAT BIT US IN THE ASS

• one wireframe for multiple screens (modules)

• wireframe → presenter →view

• protocol hell

• retain cycles

06CONCLUSION

NO SILVER BULLET… …NO S*** SHERLOCK!

USE REASON AND AVOID EARLY OPTIMISATION AND OVER-ENGENEERING.

A LOT OF GOOD READS

• http://mutualmobile.github.io/blog/2013/12/04/viper-

introduction/

• https://medium.com/ios-os-x-development/ios-

architecture-patterns-ecba4c38de52#.kxg3vn6lm

• https://www.objc.io/issues/13-architecture/viper/

• https://swifting.io/blog/2016/03/07/8-viper-to-be-

or-not-to-be/

• http://blog.soat.fr/2015/09/developper-en-ios-allegez-

vos-uiviewcontrollers-soc-separation-of-concerns/

• https://github.com/thoughtbot/liftoff

07Q&A

Recommended