The document discusses issues with the MVC architecture on iOS and proposes using the VIPER architecture as a cleaner alternative. It describes how the VIPER architecture splits code into layers including View, Interactor, Presenter, Entity and Routing layers. This decouples the logic from the UI and makes the code more reusable, testable and maintainable by separating concerns. The document provides examples of how specific responsibilities like handling user input, business logic and data access would be implemented using VIPER instead of the default iOS MVC implementation.
2. @giorgionatili#MobileTea
Who am I?
Technical Leader and Agile Coach·
Front-end Developer (test first!)
Mobile Developer (iOS, Android, Hybrid with Cordova, c++)
Organizer of Mobile Tea and New England Software
Engineer meetups
Mobile and devices instructor at General Assembly
the mobile dude!
7. @giorgionatili#MobileTea
Architecturehorrors!
What’s Wrong with This?
Controllers are not
just controllers (the
class name should
suggest this)
Controllers are to
much tied in the view
(aka IBAction and
IBOutlet)
UI element s are
configured in the
viewDidLoad
Location services,
map services, etc. are
normally used in the
controller (delegates
arena)
8. @giorgionatili#MobileTea
Xcode Defaults
The workflow of the
interface builder brings
you to do a mess!
With IBOutlet how can we
resist to configuring UI
items in the viewDidLoad?
How can we resist to
configuring segues in the
interface builder?
9. @giorgionatili#MobileTea
Why sucKh a Poor Design?
speeds up the development
decreases the learning curve
reduces the amount of code to write
More often misused and sometimes
abused, however:
14. @giorgionatili#MobileTea
View
Handle events invoking presenter’s methods
Exposes a very precise interface completely UI
agnostic
The view is passive, it waits the presenter to render
data
It’s no longer a Mess
View Controller
UI items configuration
is now delegated to
UIView subclasses
15. @giorgionatili#MobileTea
Interactor
represents a single use case in the app
contains the logic to manipulate entities (local
and remote)
communicate with the view through the presenter
It’s a wrapper around the
data communication layer
Business logic is not
anymore in the
controller
16. @giorgionatili#MobileTea
Presenter
gathers user input and send the request to the
interactor
Receives results from the interactor as simple data
structures
Updates the view
Orchestrates the
communication and
business logic
The controller logic is
now completely
decoupled
17. @giorgionatili#MobileTea
Entity(ies)
It’s a model object manipulated by the interactor
An entity is never passed around the app
The entities are simple
and maintainable
CoreData, services, etc.
are no longer mixed up
with the view
18. @giorgionatili#MobileTea
Routing
handles navigation from one view to another
owns the UIWindow and installs the
view(controller) in the window
knows how to react to presenter “signals”
Communication handled
through NotificationCenter and
Key-Value Observing
Segues and present/push
VierController(s) are not
anymore in the view