SlideShare a Scribd company logo
#Swift3Arch
Implementing Clean
Architecture in iOS
Jorge D. Ortiz-Fuentes
@jdortiz
A Canonical
Examples
production
#Swift3Arch
#Swift3Arch
Agenda
★ Goals
★ Before Clean Architecture
★ Clean Architecture Concepts
★ Implementation rules
★ Example App: RealProgrammers
★ Implement 1st User Story
★ References
#Swift3Arch
Full Version: 3d
★ MVX
• Learn
• Extract MVP
★ 1st User Story
• Use Case
• Presenter
• View
• Entity Gateway
• Initial connection
★ Connectors
• Memory
Management
• Reuse
★ 2nd user story: add
• Navigation: Modal
vs Push
• Command pattern
• Immutables
• Observation
★ 3rd user story: detail
• Identity
• Use case factories
• 2nd use case in the
same view
★ Other use cases: just
logic
★ Forward flow
synchronization
★ Dependency Injection
★ Asynchrony
• Async entity
gateway
• Other tasks
#Swift3Arch
LIVE Online Training
★ 3 days (same weekday 3 continuous weeks)
★ Máx 10 people
★ Live coding shared via video conference
★ Chat running all the time
★ Complete repo with many commits and Tests> 95%
★ Additional exercises
★ Ask as much as you want!
More info at:
http://canonicalexamples.com
Goals
#Swift3Arch
Goals
★ Understand the concepts
★ Learn the sources
★ Implement the ideas of the Clean
Architecture in a real app
★ Grow from here
Looking for
volunteer
Before Clean
Architecture
Warning:
Background Ahead!
#Swift3Arch
Before Clean Architecture
★ MVC
★ MVP
★ MVVM
– Martin Fowler
“Different people reading about MVC in
different places take different ideas from it and
describe these as 'MVC'. If this doesn't cause
enough confusion you then get the effect of
misunderstandings of MVC that develop
through a system of Chinese whispers.”
#Swift3Arch
Tricky question
★ If [Model] + [View] + [Controller /
Presenter / View Model] = [TheApp]
★ How can Controller != Presenter != View
Model?
★ Responsibilities matter!
★ Other components (patterns) might be
involved.
#Swift3Arch
The goal
★ Separation of responsibilities into roles. Is
it? Not historically. Other motivations.
Solving problem d’jour.
★ Now why?
• Testability
• Reusability
• Extensibility
#Swift3Arch
MVC: The early days
★ Separated presentation: Model <->
Presentation (= V+C)
★ Observer originated from MVC, but
observing full object (properties = scalars)
★ Variations: Passive model, i.e. model cannot
send updates (for example HTTP)
#Swift3Arch
Apple’s MVC
★ View
• Only UIView subclasses
• Show information and handle input to generate higher level events passed to controller
• Fully reusable views library. Consistent L&F
★ Controller
• Views delegate / control what’s displayed
• Receive the events and converts them into calls to the model.
• Knows about changes in the model and update what is displayed on the view. Typically a
UIViewController. Responsible of presentation logic.
★ Model
• Contain the business logic. No references to the UI.
Flow synchronization vs Observer synchronization
MVC = Composite + Strategy + Observer
Apple’s MVC
Ctrlr
ModelView
#Swift3Arch
Apple’s MVC: testability
★ The views are somebody else's (Apple's) problem.
★ Model is easy to test.
★ Controller is huge & has dependencies on the
model and on the views => Complex to test.
★ Too many levels of abstraction, only a few
methods exposed.
★ Some stuff in view controller that it is usually not
tested.
MVP
MVP
Presenter ModelView
Events Operations
Changes Changes
MVVM
MVVM
View Model ModelView
Events & Info Operations
Changes Changes
Clean Architecture
Concepts
#Swift3Arch
Clean Architecture
★ Uncle Bob’s (Robert C. Martin’s) architecture
★ Based in Onion, in turn based in hexagonal,
DCI and some others
Clean Architecture
App
Delegate
View (VC) Presenter Interactor
Entity
Gateway
Connector
Persistance FW
View
Network
LocationFW
Presenter
Entity Gateway
Clean Architecture
Interactor
Entity
Implementation
Rules
#Swift3Arch
Rules
★ We are going to develop one module at a
time
★ Follow the dependency rules
★ YAGNI
★ No early optimization applied
★ It is easy to add tests, but no TDD in 3h
OK??
Example App:
RealProgrammers
#Swift3Arch
Features
★ Add potential candidates (Name, email, and important skills)
★ Show list of programmers with relative interview date
★ Remove candidates from list
★ Edit the data of any candidate
★ Contact candidate by email
★ Sync between devices
★ Universal app
★ Eye candy
★ iOS/macOS/watchOS/tvOS?
★ Credits
#Swift3Arch
MVP Features
★ Add potential candidates (Name, email, and important skills)
★ Show list of programmers with relative interview date
★ Remove candidates from list
★ Edit the data of any candidate
★ Contact candidate by email
★ Sync between devices
★ Universal app
★ Eye candy
★ iOS/macOS/watchOS/tvOS?
★ Credits
Implementing the
1st User Story
I feel like I could
Take On the
World!
#Swift3Arch
First User Story
★ Show a list of data elements to the user.
Interactor
View (VC) Presenter
Show

Programmers
Entity
Gateway
#Swift3Arch
Interactor
★ Grab data from the entity gateway
★ Convert it to what is needed to be
presented
★ Pass the results to the presenter
★ Start by defining the protocols
Presenter
View (VC)
Programmers

List
Show

Programmers
Entity
Gateway
#Swift3Arch
Presenter
★ Direction: only from interactor to view
★ Configure the (dumb) view with the data
provided to it
★ Create the protocol for the view (Simplest
wins!)
View
Programmers
TableVC
Programmers

List
Show

Programmers
Entity
Gateway
#Swift3Arch
View
★ Combination of Views + View Controller
★ Make it dumb (passive), but useful
★ Tell the presenter about the relevant events
★ Keep them decoupled
Presenter
Programmers
TableVC
Programmers

List
Show

Programmers
Entity
Gateway
#Swift3Arch
Back to the Presenter
★ Implement responses to the user events.
★ Use the interactor
★ Add presentation logic to the presenter part
#Swift3Arch
Presentation Logic
★ Date should be relative (“Today”, “1d ago”,
“2w ago”)
★ That means current date is a dependency
that we want to control for tests
★ Use lazy instantiation for the current date
Entity Gateway
Programmers
TableVC
Programmers

List
Show

Programmers
Entity
Gateway
#Swift3Arch
Entity Gateway
★ Basic
★ Defer the decision of the persistence
framework for later.
★ Implement the minimum functionality in a
basic object.
★ Implications of the repository pattern.
References
#Swift3Arch
References
★ http://martinfowler.com/eaaDev/
uiArchs.html
★ https://blog.8thlight.com/uncle-bob/
2012/08/13/the-clean-architecture.html
★ https://cleancoders.com/episode/clean-
code-episode-7/show
Thank
you!
@jdortiz
#Swift3Arch

More Related Content

PDF
iOS advanced architecture workshop 3h edition
PDF
To Protect & To Serve
PDF
Infinum Android Talks #13 - Developing Android Apps Like Navy Seals by Ivan Kušt
PDF
Android clean architecture workshop 3h edition
PPTX
Patterns in JavaScript
PDF
The Python in the Apple
PDF
MVVM on iOS
PPTX
Advanced AngularJS Tips and Tricks
iOS advanced architecture workshop 3h edition
To Protect & To Serve
Infinum Android Talks #13 - Developing Android Apps Like Navy Seals by Ivan Kušt
Android clean architecture workshop 3h edition
Patterns in JavaScript
The Python in the Apple
MVVM on iOS
Advanced AngularJS Tips and Tricks

What's hot (20)

PPTX
Introduction to angular 2
PPTX
React Native
PDF
From zero to hero with React Native!
PPTX
Angular from a Different Angle
PDF
ColdBox Hierarchical MVC - Transform Your Monolith
PDF
The Continuous PHP Pipeline
PDF
Matteo Manchi - React Native for multi-platform mobile applications - Codemot...
PPTX
Integration Testing with Selenium
PPTX
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
PPTX
Automating JavaScript testing with Jasmine and Perl
PPTX
Functional programing jargon
PDF
Scaling up development of a modular code base
PPTX
Back to the ng2 Future
PDF
Conquering AngularJS Limitations
PDF
WilmingtonJS - React Native Under the Hood
PDF
A Separation of Concerns: Clean Architecture on Android
PDF
Laravel.IO A Use-Case Architecture
PDF
Do you really want to go fully micro?
PDF
Building Better AngularJS 1.X Apps With TypeScript
PPTX
Fast Track introduction to ASP.NET MVC
Introduction to angular 2
React Native
From zero to hero with React Native!
Angular from a Different Angle
ColdBox Hierarchical MVC - Transform Your Monolith
The Continuous PHP Pipeline
Matteo Manchi - React Native for multi-platform mobile applications - Codemot...
Integration Testing with Selenium
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Automating JavaScript testing with Jasmine and Perl
Functional programing jargon
Scaling up development of a modular code base
Back to the ng2 Future
Conquering AngularJS Limitations
WilmingtonJS - React Native Under the Hood
A Separation of Concerns: Clean Architecture on Android
Laravel.IO A Use-Case Architecture
Do you really want to go fully micro?
Building Better AngularJS 1.X Apps With TypeScript
Fast Track introduction to ASP.NET MVC
Ad

Viewers also liked (20)

PDF
Introduction to VIPER Architecture
PDF
Jorge D. Ortiz Fuentes "Hands on Implementation of Clean Architecture for And...
PDF
iOS viper presentation
PDF
From mvc to viper
PPTX
VIPER - Design Pattern
PPTX
iOS Coding Best Practices
PDF
TDD for the masses
PDF
Architectural superpowers
PPTX
VIPER Architecture
PPTX
Cocoa and MVC in ios, iOS Training Ahmedbad , iOS classes Ahmedabad
PDF
10 tips for a reusable architecture
PDF
Dependence day insurgence
PDF
Why the Dark Side should use Swift and a SOLID Architecture
PDF
Clear the UIViewController Mess
PDF
Application architecture doesn't have to suck
PDF
"Clean" Architecture
PDF
Rambler.iOS #5: VIPER a la Rambler
PDF
iOS Zagreb Meetup #02 - Clean architecture in iOS apps (Leonard Beus @ Five)
PPTX
[SIP 2015] iOS Proposal: VIPER
PDF
Infinum iOS Talks #4 - Making our VIPER more reactive
Introduction to VIPER Architecture
Jorge D. Ortiz Fuentes "Hands on Implementation of Clean Architecture for And...
iOS viper presentation
From mvc to viper
VIPER - Design Pattern
iOS Coding Best Practices
TDD for the masses
Architectural superpowers
VIPER Architecture
Cocoa and MVC in ios, iOS Training Ahmedbad , iOS classes Ahmedabad
10 tips for a reusable architecture
Dependence day insurgence
Why the Dark Side should use Swift and a SOLID Architecture
Clear the UIViewController Mess
Application architecture doesn't have to suck
"Clean" Architecture
Rambler.iOS #5: VIPER a la Rambler
iOS Zagreb Meetup #02 - Clean architecture in iOS apps (Leonard Beus @ Five)
[SIP 2015] iOS Proposal: VIPER
Infinum iOS Talks #4 - Making our VIPER more reactive
Ad

Similar to Clean architecture workshop (20)

PDF
iOS architecture patterns
PPTX
iOS Architecture
PDF
Ui design patterns
PDF
"iOS: MVVMC" - Aleksandr Nikolajev from Mooncascade
PPSX
SOLID Principles and The Clean Architecture
PDF
PDF
Introduction of Xcode
PPTX
Training on iOS app development - Samesh Swongamikha & Neetin Sharma
PDF
Architecting Alive Apps
PDF
Session 7 - Overview of the iOS7 app development architecture
PDF
201710 Fly Me to the View - iOS Conf SG
PDF
Clean Architecture
PPT
ios basics
PDF
Алексей Демедецкий: How to: RAC, TDD, MVVM
PDF
Models used in iOS programming, with a focus on MVVM
PDF
iOS Development Introduction
PDF
Lecture 1 slides
PDF
Intro to iOS Application Architecture
PDF
Exploring MVVM-C
PDF
Distributing information on iOS
iOS architecture patterns
iOS Architecture
Ui design patterns
"iOS: MVVMC" - Aleksandr Nikolajev from Mooncascade
SOLID Principles and The Clean Architecture
Introduction of Xcode
Training on iOS app development - Samesh Swongamikha & Neetin Sharma
Architecting Alive Apps
Session 7 - Overview of the iOS7 app development architecture
201710 Fly Me to the View - iOS Conf SG
Clean Architecture
ios basics
Алексей Демедецкий: How to: RAC, TDD, MVVM
Models used in iOS programming, with a focus on MVVM
iOS Development Introduction
Lecture 1 slides
Intro to iOS Application Architecture
Exploring MVVM-C
Distributing information on iOS

More from Jorge Ortiz (20)

PDF
Tell Me Quando - Implementing Feature Flags
PDF
Unit Test your Views
PDF
Control your Voice like a Bene Gesserit
PDF
Kata gilded rose en Golang
PDF
CYA: Cover Your App
PDF
Refactor your way forward
PDF
Home Improvement: Architecture & Kotlin
PDF
Architectural superpowers
PDF
Escape from Mars
PDF
7 Stages of Unit Testing in iOS
PDF
Building for perfection
PDF
TDD by Controlling Dependencies
PDF
Unit testing in swift 2 - The before & after story
PDF
Core Data in Modern Times
PDF
Swift testing ftw
PDF
7 stages of unit testing
PDF
Travel with your mock server
PDF
Kata tdd
KEY
Scrum para uno
PDF
Core data + i cloud
Tell Me Quando - Implementing Feature Flags
Unit Test your Views
Control your Voice like a Bene Gesserit
Kata gilded rose en Golang
CYA: Cover Your App
Refactor your way forward
Home Improvement: Architecture & Kotlin
Architectural superpowers
Escape from Mars
7 Stages of Unit Testing in iOS
Building for perfection
TDD by Controlling Dependencies
Unit testing in swift 2 - The before & after story
Core Data in Modern Times
Swift testing ftw
7 stages of unit testing
Travel with your mock server
Kata tdd
Scrum para uno
Core data + i cloud

Recently uploaded (20)

PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
ISO 45001 Occupational Health and Safety Management System
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Nekopoi APK 2025 free lastest update
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
Odoo POS Development Services by CandidRoot Solutions
PPTX
Introduction to Artificial Intelligence
PPTX
Online Work Permit System for Fast Permit Processing
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
System and Network Administration Chapter 2
PPTX
ai tools demonstartion for schools and inter college
PDF
top salesforce developer skills in 2025.pdf
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
2025 Textile ERP Trends: SAP, Odoo & Oracle
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
ISO 45001 Occupational Health and Safety Management System
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Nekopoi APK 2025 free lastest update
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
How to Choose the Right IT Partner for Your Business in Malaysia
ManageIQ - Sprint 268 Review - Slide Deck
Upgrade and Innovation Strategies for SAP ERP Customers
Odoo POS Development Services by CandidRoot Solutions
Introduction to Artificial Intelligence
Online Work Permit System for Fast Permit Processing
PTS Company Brochure 2025 (1).pdf.......
System and Network Administration Chapter 2
ai tools demonstartion for schools and inter college
top salesforce developer skills in 2025.pdf
VVF-Customer-Presentation2025-Ver1.9.pptx

Clean architecture workshop