SlideShare a Scribd company logo
Not Your
Granddaddy's
Architecture
Building Modularity into View Controller Hierarchies
Modular View Controller Hierarchies
Modular View Controller Hierarchies
The following takes place
in an alternate reality
Meet Jax
Modular View Controller Hierarchies
Jax is a super
awesome app
developer
or at least, he
thinks he is
Jax pounds red bulls and
talks about how sick his
coding skills are.
Modular View Controller Hierarchies
Most importantly,
he loves watermelon
Modular View Controller Hierarchies
Jax just got hired
working on the next
world changing app.
My Pet Alien
My Pet Alien is an
app that tracks your
pet alien's health,
and will alert you
if your alien
is getting sick.
Modular View Controller Hierarchies
"Sure, that will
take 2 months,
EASY.” - Jax
Modular View Controller Hierarchies
Jax spends the next 2 months
pounding red bulls, building
flows in Interface builder,
and coding the entire app.
(we’re going to jump into
Jax’s train of thought as
he builds this out)
Modular View Controller Hierarchies
Jax thinks back
to 2009…
Modular View Controller Hierarchies
Jax fell in love
with iOS at WWDC
Modular View Controller Hierarchies
That’s where Jax
learned how to build
navigation flows.
Modular View Controller Hierarchies
He even got to see
Scott on stage
If you’re asking
who Scott is…
Modular View Controller Hierarchies
Jax looks at the
designs…
Modular View Controller Hierarchies
“Apps are made of
view controller
hierarchies”
“Ok, I need a nav
controller and three
content view controllers”
Jax begins
sketching this out
Container View Controller
Content View Controller
Navigation Controller, Tab Controller, Page
View Controller, Split View Controller, custom
Table View Controller, Collection View
Controller, custom
View Controller Hierarchy
Home View
Controller
Table View
Controller
Detail View
Controller
WindowNavigation Controller
Root
View Controller
Jax opens up a
storyboard and
starts building.
Modular View Controller Hierarchies
Lets review how
this works
View Controller Hierarchy
Home View
Controller
Table View
Controller
Detail View
Controller
WindowNavigation Controller
Root
View Controller
View Controller Hierarchy
Home View
Controller
Table View
Controller
Detail View
Controller
Navigation Controller
View Controller Hierarchy
On App Launch…
On App Launch…
Storyboard
On App Launch…
Storyboard
Storyboard
On User Interaction…
Creates Table View Controller
Storyboard
On User Interaction…
Creates Table View Controller
Storyboard
On User Interaction…
Calls Prepare for Segue
On User Interaction…
HomeViewController.swift
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
On User Interaction…
HomeViewController.swift
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
Match Segue string
On User Interaction…
HomeViewController.swift
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
Match Segue string
Cast new VC
On User Interaction…
HomeViewController.swift
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
Match Segue string
Cast new VC
Set up new VC
Storyboard Pushes View Controller onto Stack
On User Interaction…
Storyboard
On Cell Selection…
On Cell Selection…
TableViewController.swift
func tableView(tableView: UITableView,
didSelectRowAtIndexPath indexPath: NSIndexPath) {
On Cell Selection…
TableViewController.swift
func tableView(tableView: UITableView,
didSelectRowAtIndexPath indexPath: NSIndexPath) {
Store Selected ID
On Cell Selection…
TableViewController.swift
func tableView(tableView: UITableView,
didSelectRowAtIndexPath indexPath: NSIndexPath) {
Store Selected ID
Perform Segue
Storyboard Creates Detail View Controller
On Cell Selection…
Storyboard Creates Detail View Controller
On Cell Selection…
Storyboard Calls Prepare for Segue
On Cell Selection…
On Cell Selection…
TableViewController.swift
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
On Cell Selection…
TableViewController.swift
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
Match Segue string
On Cell Selection…
TableViewController.swift
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
Match Segue string
Cast new VC
On Cell Selection…
TableViewController.swift
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
Match Segue string
Cast new VC
Set up new VC
Storyboard Pushes View Controller onto Stack
On Cell Selection…
2 months later,
Jax is done!
Modular View Controller Hierarchies
Modular View Controller Hierarchies
Success!
Modular View Controller Hierarchies
Jax looks at
iTunes Connect
Modular View Controller Hierarchies
The downloads are
pouring in.
The investors are
interested.
Funded!
Turns out there’s a
lot of alien pet
owners out there!
With all the new $ and
feature requests, the
company decides to hire
another engineer.
Meet Jiles
Jiles is an application
developer from Great
Britain. A seasoned
professional.
Jiles and
Jax meet.
Jiles congratulates
Jax on his success.
Modular View Controller Hierarchies
Jiles asks Jax what he
thinks of the application
architecture he has
designed.
Modular View Controller Hierarchies
Jax says its the
best, everything is
perfect.
Jax tells the company
he’s taking a month long
vacation to Thailand.
Peace!
Modular View Controller Hierarchies
Jiles feels good about
his new position and
(seemingly) solid
codebase.
The next day…
The project manager asks
Jiles to include the pet
list screen before the
login screen.
and to place a new detail
screen between the pet
list and pet detail.
Jiles thinks to himself, ya
know, Jax said the architecture
was solid, this should take me
about 30 minutes.
Modular View Controller Hierarchies
Modular View Controller Hierarchies
Jax starts working
on moving the list
and detail screens.
Easy!
Easy!
Easy!
Easy!
Easy!
Easy!
So he thought…
!?
EMPTY!
Modular View Controller Hierarchies
What’s going on here?
Let’s review how Jax
built this…
On User Interaction…
Storyboard
On User Interaction…
Creates Table View Controller
Storyboard
On User Interaction…
Creates Table View Controller
Storyboard
On User Interaction…
Calls Prepare for Segue
On User Interaction…
HomeViewController.swift
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
Match Segue string
Cast new VC
Set up new VC
On User Interaction…
HomeViewController.swift
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
Match Segue string
Cast new VC
Set up new VC
Home VC fetches Table VC’s data
Isolate content view controllers!
Content controllers should know how to retrieve their own data
!?
EMPTY!
!?
COUPLED CONTENT
Viewcontrollers!
It’s now 2 am…
After an hour of re-
wiring, Jax moves on to
adding the new screen.
“Well at least this
one will be easy!”
Easy!
Easy!
So he thought…
Modular View Controller Hierarchies
What’s going on here?
Let’s review how Jax
built this…
On Cell Selection…
On Cell Selection…
TableViewController.swift
func tableView(tableView: UITableView,
didSelectRowAtIndexPath indexPath: NSIndexPath) {
On Cell Selection…
TableViewController.swift
func tableView(tableView: UITableView,
didSelectRowAtIndexPath indexPath: NSIndexPath) {
Store Selected ID
On Cell Selection…
TableViewController.swift
func tableView(tableView: UITableView,
didSelectRowAtIndexPath indexPath: NSIndexPath) {
Store Selected ID
Perform Segue
Storyboard Creates New View Controller
On Cell Selection…
Storyboard Creates New View Controller
On Cell Selection…
Storyboard Calls Prepare for Segue
On Cell Selection…
On Cell Selection…
TableViewController.swift
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
On Cell Selection…
TableViewController.swift
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
Match Segue string
On Cell Selection…
TableViewController.swift
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
Match Segue string
Cast new VC
Set up new VC
On Cell Selection…
TableViewController.swift
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
Match Segue string
Cast new VC
Set up new VC
Table VC doesn’t know NewVC
Table VC only knows DetailVC
COUPLED CONTENT
Viewcontrollers!
Isolate
content view controllers
What are we losing?
• Ability to
• re-order content view controllers
• reuse content view controllers
Next day…
Jiles comes in looking
like he was hit by a
train and mauled by some
cats.
Modular View Controller Hierarchies
Jiles delivers,
but is exhausted
Jiles thinks...
he should be able to move
this list anywhere in the
app, and it should just
work!
Jiles thinks...
View controllers should be
able to live on their own.
They should not depend on
the container they are in
and they should not
depend on sibling
content controllers.
Sometime in
the Future...
Modular View Controller Hierarchies
Jiles goes to WWDC in
search of a better view
controller architecture
Jiles meets John in
line for the
keynote
Modular View Controller Hierarchies
John asks,
“how’s it going, how
was your last project?”
Modular View Controller Hierarchies
Jiles explains the
problems he faced,
he tells John,
“there must be a
better way!”
John has experienced
the exact same
problems as Jiles
John says, "I've
found a better way"
Jiles is happy... and
eager to learn more!
Modular View Controller Hierarchies
John starts
explaining…
So where should logic go?
So where should logic go?
Can’t go here
So where should logic go?
Can’t go here
So where should logic go?
Can’t go here
So where?
So where should logic go?
Navigation View Controller
So where should logic go?
Navigation View Controller
So where should logic go?
Navigation View Controller why not here?
So where should logic go?
UINavigationController
IS
a container view controller
Subclassing isn’t
always
evil
How would this work?
Content View
Controllers
Think of as async task
Inputs and Outcomes
Inputs and Outcomes
After init, provide input
Inputs and Outcomes
When finished, report outcome
Input
• Either
• initializer arguments
• public variable properties
Outcome
• Either
• onComplete closure (selectedId: String)->()
• leverage targetViewControllerForAction
class TableViewController: UITableViewController {
// Input
var userId: String?
// Outcome
var onComplete: ((selectedId: String)->())?
}
Input-Outcome Based VC
// Inside Container View Controller...
let tableVC = TableViewController(style: .Plain)
tableVC.userId = loggedInUserId
tableVC.onComplete = { selectedId in
// Container VC decides where to go next
}
Container’s Usage
Back to our navigation
controller…
On App Launch
Creates HomeVC
MyNavigationController.swift
let homeVC = HomeVC()
Creates HomeVC
MyNavigationController.swift
let homeVC = HomeVC()
Pushes HomeVC
MyNavigationController.swift
pushViewController(homeVC, animated: false))
On User Interaction…
HomeViewController.swift
onComplete()
On User Interaction…
MyNavigationController.swift
let tableVC = TableViewController()
Nav controller manages
content view controllers
On User Interaction…
MyNavigationController.swift
let tableVC = TableViewController()
Nav controller manages
content view controllers
On User Interaction…
MyNavigationController.swift
pushViewController(tableVC, animated: true)
On Cell Selection
TableViewController.swift
func tableView(tableView: UITableView,
didSelectRowAtIndexPath indexPath: NSIndexPath) {
On Cell Selection
TableViewController.swift
onComplete(selectedId: viewModelObject.id)
On Cell Selection
MyNavigationController.swift
let detailVC = DetailViewController(modelId: selectedId)
On Cell Selection
MyNavigationController.swift
let detailVC = DetailViewController(modelId: selectedId)
On Cell Selection
MyNavigationController.swift
let detailVC = DetailViewController(modelId: selectedId)
On Cell Selection
MyNavigationController.swift
pushViewController(detailVC, animated: true)
Demo!
Composition
Modular View Controller Hierarchies
Remember
Dependencies
Content View Controllers should not depend on
• a specific container view controller class
• sibling content view controllers
Think of view controllers as lego blocks
If you liked this,
there’s more
Elements
Josh Berlin
Collection View Master
joshaberlin@gmail.com
@jab2109
René Cacheaux
iOS Architect
rene.cacheaux@mutualmobile.com
rene.cacheaux@gmail.com
@RCachATX
Modular View Controller Hierarchies

More Related Content

PDF
Parallactic Collection Views
PDF
Bringing Swift into your Objective-C Projects
PDF
Writing Code for Humans, not Computers
PPTX
How native is React Native? | React Native vs Native App Development
PDF
Putting the Native in React Native - React Native Boston
PPTX
React Native - Unleash the power of React in your device - Eduard Tomàs - Cod...
PDF
An iOS Developer's Perspective on React Native
PDF
Optimizing React Native views for pre-animation
Parallactic Collection Views
Bringing Swift into your Objective-C Projects
Writing Code for Humans, not Computers
How native is React Native? | React Native vs Native App Development
Putting the Native in React Native - React Native Boston
React Native - Unleash the power of React in your device - Eduard Tomàs - Cod...
An iOS Developer's Perspective on React Native
Optimizing React Native views for pre-animation

What's hot (20)

PDF
Android programming-basics
PDF
Intro to react native
PPTX
React Native for ReactJS Devs
PDF
I Love APIs - Oct 2015
PPTX
Titanium Appcelerator - Beginners
PPTX
AHOY FB Hack Day 2017
PDF
Introduction to React Native & Rendering Charts / Graphs
PDF
Lecture 12: React-Native Firebase Authentication
PPTX
Appcelerator Titanium Intro
PDF
Experiences building apps with React Native @UtrechtJS May 2016
PDF
React Native in a nutshell
PPTX
iOS Coding Best Practices
PDF
React Native
PPTX
Getting started with Appcelerator Titanium
PDF
Introduction to react native
PDF
Introduction to React Native
PDF
iPhone University Developer Program
PDF
Swift
PPTX
Xamarin.Android Introduction
PPTX
Android programming-basics
Intro to react native
React Native for ReactJS Devs
I Love APIs - Oct 2015
Titanium Appcelerator - Beginners
AHOY FB Hack Day 2017
Introduction to React Native & Rendering Charts / Graphs
Lecture 12: React-Native Firebase Authentication
Appcelerator Titanium Intro
Experiences building apps with React Native @UtrechtJS May 2016
React Native in a nutshell
iOS Coding Best Practices
React Native
Getting started with Appcelerator Titanium
Introduction to react native
Introduction to React Native
iPhone University Developer Program
Swift
Xamarin.Android Introduction
Ad

Similar to Modular View Controller Hierarchies (20)

PDF
Testing view controllers with Quick and Nimble
ODP
Apotomo Goes Rubyconf
PPTX
IOS Storyboards
PDF
Javascript spaghetti stirtrek_5_17
PDF
React Native custom components
KEY
Debugging: Or How I Learned To Stop Worrying and Love EXC_BAD_ACCESS
PDF
An Event Apart Boston: Principles of Unobtrusive JavaScript
PDF
Arquillian: Effective tests from the client to the server
PDF
Rethink Async with RXJS
PDF
Rethink Async With RXJS
PDF
Rethink Async with RXJS
PDF
Mattia Manzati - Real-World MobX Project Architecture - Codemotion Rome 2019
PPT
Building Rich User Experiences Without JavaScript Spaghetti
PPT
GUI design using JAVAFX.ppt
PDF
Delegateless Coordinator
PDF
iOS storyboard
PDF
Javascript
PDF
Formacion en movilidad: Conceptos de desarrollo en iOS (II)
PDF
React && React Native workshop
PDF
Xtext beyond the defaults - how to tackle performance problems
Testing view controllers with Quick and Nimble
Apotomo Goes Rubyconf
IOS Storyboards
Javascript spaghetti stirtrek_5_17
React Native custom components
Debugging: Or How I Learned To Stop Worrying and Love EXC_BAD_ACCESS
An Event Apart Boston: Principles of Unobtrusive JavaScript
Arquillian: Effective tests from the client to the server
Rethink Async with RXJS
Rethink Async With RXJS
Rethink Async with RXJS
Mattia Manzati - Real-World MobX Project Architecture - Codemotion Rome 2019
Building Rich User Experiences Without JavaScript Spaghetti
GUI design using JAVAFX.ppt
Delegateless Coordinator
iOS storyboard
Javascript
Formacion en movilidad: Conceptos de desarrollo en iOS (II)
React && React Native workshop
Xtext beyond the defaults - how to tackle performance problems
Ad

Recently uploaded (20)

PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Empathic Computing: Creating Shared Understanding
PDF
Chapter 2 Digital Image Fundamentals.pdf
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
PDF
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Advanced Soft Computing BINUS July 2025.pdf
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PDF
Modernizing your data center with Dell and AMD
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
PPTX
Big Data Technologies - Introduction.pptx
PPT
Teaching material agriculture food technology
PDF
Electronic commerce courselecture one. Pdf
PPTX
Cloud computing and distributed systems.
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PDF
Advanced IT Governance
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Empathic Computing: Creating Shared Understanding
Chapter 2 Digital Image Fundamentals.pdf
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Advanced methodologies resolving dimensionality complications for autism neur...
Reach Out and Touch Someone: Haptics and Empathic Computing
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Advanced Soft Computing BINUS July 2025.pdf
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
Modernizing your data center with Dell and AMD
madgavkar20181017ppt McKinsey Presentation.pdf
Big Data Technologies - Introduction.pptx
Teaching material agriculture food technology
Electronic commerce courselecture one. Pdf
Cloud computing and distributed systems.
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
Advanced IT Governance

Modular View Controller Hierarchies