SlideShare a Scribd company logo
Intro to iOS Application Architecture
INTRODUCTION TO
ARCHITECTING YOUR IOS APP
AGENDA
Goals of software architecture
Design guidelines
Practical tips
GOALS OF SOFTWARE
ARCHITECTURE
GOALS OF SOFTWARE
ARCHITECTURE
Code is comprehensible for other developers
Code can adopt to changing requirements
Code can be shared within the project and throughout
multiple projects
THINK IN DOMAINS NOT IN
OBJECTS
DOMAINS NOT OBJECTS
Business
Logic
Persistence
UI/UX
Code
NetworkingReusability
User Object
Trip Object
DOMAINS NOT OBJECTS
Business
Logic
Persistence
UI/UX
Code
Networking
Reusability
User Object
Trip Object
User View
Trip View
SINGLE RESPONSIBILITY
PRINCIPLE
SINGLE RESPONSIBILITY PRINCIPLE
Avoid having many responsibilities within a single class
Very important when implementing UIViewController
subclasses
Bad View Controller handles: Persistence, Business
Logic, View Logic, etc.
ENCAPSULATE
ENCAPSULATE
Every component should know as little as possible
about its surrounding components 

→ reduces dependencies between components
How can this be accomplished?

→ small interfaces for communication
ENCAPSULATE
Add Trip View Controller Core Data Client
startSavingNewTrip(newTrip)
displayError(nameError)
setNameOfTrip(“SF Trip”)
disableSaveButton()
Classes are poorly encapsulated and very dependent on 

each other - very hard to change code in any of the two classes
ENCAPSULATE
Add Trip View Controller Core Data Client
saveTrip(newTrip)
saveErrorOccurred(error)
Small communication interface 

reduces dependencies!
PRACTICAL TIPS
#1 AVOID THE MASSIVE
VIEW CONTROLLER
AVOID THE MASSIVE VIEW
CONTROLLER
Rule of thumb: A View Controller with > 300 lines is
probably doing more than it should do
THINGS A VIEW CONTROLLER
SHOULD DO
Listen to callbacks from the View → invoke methods on
the model layer → send responses from model back to
the view
THINGS A VIEW CONTROLLER
SHOULD NOT DO
Construct complex network requests
Construct complex database queries
Take care of object serialization / deserialization
#2 DEFINE EXPRESSIVE APIS
DEFINE EXPRESSIVE APIS
E.g. instead of exposing details of the network layer,
provide functions with a simple interface:

func fetchAllUsers(callback: [User] -> ())



fetchAllUsers { users in
print(users)
}
#3 USE VIEW OBJECTS
USE VIEW OBJECTS
View objects encapsulate multiple properties that are
relevant for a type to be displayed by a custom view
This is preferred over setting individual properties from
outside the view
USE VIEW OBJECTS
class UserView: UIView {
@IBOutlet var nameLabel: UILabel!
@IBOutlet var profilePictureImageView: UIImageView!
var user: User? {
didSet {
nameLabel.text = user?.name
profilePictureImageView.image = user?.profilePicture
}
}
}
let userView = UserView()
let currentUser = User()
currentUser.name = "TestUser"
userView.user = currentUser
View encapsulates how an 

object is displayed!
USE VIEW OBJECTS
class UserView: UIView {
@IBOutlet var nameLabel: UILabel!
@IBOutlet var profilePictureImageView: UIImageView!
}
let userView = UserView()
let currentUser = User()
currentUser.name = "TestUser"
userView.nameLabel.text = currentUser.name
userView.profilePictureImageView.image = currentUser.profilePicture
Code that uses UserView now

depends on its UI components.

Violates encapsulation!
#4 BE WARY OF INHERITANCE
BE WARY OF INHERITANCE
Base View
Class
Trip View
You can only inherit one set of functionality
You tend to inherit functionality that you don’t need
More modular alternatives:
Functions that can operate on relevant types 

(using generics)
Protocols & Protocol Extensions
BE WARY OF INHERITANCE
Base View
Class
Trip View
More Specific
Trip View
Trip View
Error

Representable
Restorable Presentable
SUMMARY
SUMMARY
Divide code into logical domains
Strive for each unit of code having a single responsibility
Consider using protocols instead of inheritance
Define narrow and expressive APIs that hide
implementation details of other units of code and
reduce dependencies between your units
ADDITIONAL RESOURCES
ADDITIONAL RESOURCES
Talk: Refactor the Mega-Controller
WWDC 2015: Protocol Oriented Programming
WWDC 2014: Advanced Application Architecture
Ray Wenderlich: Protocol Oriented programming

More Related Content

What's hot (20)

PPTX
MVC Training Part 1
Lee Englestone
 
PPTX
Its time to React.js
Ritesh Mehrotra
 
PPTX
Angular 4
Saurabh Juneja
 
PPTX
React & Redux JS
Hamed Farag
 
PPTX
Introduction to AngularJS
David Parsons
 
ODP
Introduction to Knockout Js
Knoldus Inc.
 
PPTX
AngularJS Beginners Workshop
Sathish VJ
 
PPT
Entity frameworks101
Rich Helton
 
PPTX
AngularJs (1.x) Presentation
Raghubir Singh
 
PDF
Dicoding Developer Coaching #31: Android | Menerapkan Clean Architecture di A...
DicodingEvent
 
PDF
React js
Rajesh Kolla
 
PPTX
Angular Data Binding
Jennifer Estrada
 
PDF
iOS viper presentation
Rajat Datta
 
PDF
AngularJS 101 - Everything you need to know to get started
Stéphane Bégaudeau
 
PDF
Automation strategies for agile testing Gaurav bansal
India Scrum Enthusiasts Community
 
PPTX
Domain Driven Design for Angular
Jennifer Estrada
 
PPTX
Angular jS Introduction by Google
ASG
 
PPTX
Valentine with Angular js - Introduction
Senthil Kumar
 
PPTX
CodeIgniter 101 Tutorial
Konstantinos Magarisiotis
 
PDF
Angular js
Knoldus Inc.
 
MVC Training Part 1
Lee Englestone
 
Its time to React.js
Ritesh Mehrotra
 
Angular 4
Saurabh Juneja
 
React & Redux JS
Hamed Farag
 
Introduction to AngularJS
David Parsons
 
Introduction to Knockout Js
Knoldus Inc.
 
AngularJS Beginners Workshop
Sathish VJ
 
Entity frameworks101
Rich Helton
 
AngularJs (1.x) Presentation
Raghubir Singh
 
Dicoding Developer Coaching #31: Android | Menerapkan Clean Architecture di A...
DicodingEvent
 
React js
Rajesh Kolla
 
Angular Data Binding
Jennifer Estrada
 
iOS viper presentation
Rajat Datta
 
AngularJS 101 - Everything you need to know to get started
Stéphane Bégaudeau
 
Automation strategies for agile testing Gaurav bansal
India Scrum Enthusiasts Community
 
Domain Driven Design for Angular
Jennifer Estrada
 
Angular jS Introduction by Google
ASG
 
Valentine with Angular js - Introduction
Senthil Kumar
 
CodeIgniter 101 Tutorial
Konstantinos Magarisiotis
 
Angular js
Knoldus Inc.
 

Similar to Intro to iOS Application Architecture (20)

PPTX
04 objective-c session 4
Amr Elghadban (AmrAngry)
 
PDF
IOS APPs Revision
Muhammad Amin
 
PPTX
Ios development 2
elnaqah
 
PPTX
Compose In Practice
Kelvin Harron
 
PDF
Swift
Larry Ball
 
PDF
Introduction of Xcode
Dhaval Kaneria
 
PDF
iPhone SDK dev sharing - the very basics
kenshin03
 
PDF
React Native for multi-platform mobile applications
Matteo Manchi
 
PPTX
VIPER Architecture
Ahmed Lotfy
 
PPTX
MVVM Design Pattern NDC2009
Jonas Follesø
 
PDF
Mobile Application Development -Lecture 07 & 08.pdf
AbdullahMunir32
 
PDF
Stmik bandung
farid savarudin
 
PPTX
Mvc ppt
Gowarthini
 
PDF
Highly Scalable User Experience Design: Vaadin and Magnolia
Magnolia
 
PPTX
Objective c design pattens-architetcure
BITs Information Technology Consultants Co., Ltd.
 
PPT
ios basics
Muthu Sabarinathan
 
PDF
Swiz DAO
devaraj ns
 
PDF
Model View Presenter
rendra toro
 
PDF
Data binding w Androidzie
The Software House
 
ODP
Design Patterns in ZK: Java MVVM as Model-View-Binder
Simon Massey
 
04 objective-c session 4
Amr Elghadban (AmrAngry)
 
IOS APPs Revision
Muhammad Amin
 
Ios development 2
elnaqah
 
Compose In Practice
Kelvin Harron
 
Swift
Larry Ball
 
Introduction of Xcode
Dhaval Kaneria
 
iPhone SDK dev sharing - the very basics
kenshin03
 
React Native for multi-platform mobile applications
Matteo Manchi
 
VIPER Architecture
Ahmed Lotfy
 
MVVM Design Pattern NDC2009
Jonas Follesø
 
Mobile Application Development -Lecture 07 & 08.pdf
AbdullahMunir32
 
Stmik bandung
farid savarudin
 
Mvc ppt
Gowarthini
 
Highly Scalable User Experience Design: Vaadin and Magnolia
Magnolia
 
Objective c design pattens-architetcure
BITs Information Technology Consultants Co., Ltd.
 
ios basics
Muthu Sabarinathan
 
Swiz DAO
devaraj ns
 
Model View Presenter
rendra toro
 
Data binding w Androidzie
The Software House
 
Design Patterns in ZK: Java MVVM as Model-View-Binder
Simon Massey
 
Ad

More from Make School (20)

PDF
Memory Management on iOS
Make School
 
PDF
Swift Objective-C Interop
Make School
 
PDF
Client Server Synchronization iOS
Make School
 
PDF
Dependency Management on iOS
Make School
 
PDF
Xcode Project Infrastructure
Make School
 
PDF
Localization and Accessibility on iOS
Make School
 
PDF
Distributing information on iOS
Make School
 
PDF
Swift 2 intro
Make School
 
PDF
Error Handling in Swift
Make School
 
PDF
Client Server Communication on iOS
Make School
 
PDF
Standard libraries on iOS
Make School
 
PDF
Make School 2017 - Mastering iOS Development
Make School
 
PDF
Multithreading on iOS
Make School
 
PDF
Advanced Core Data
Make School
 
PDF
Intro to Core Data
Make School
 
PDF
Persistence on iOS
Make School
 
PDF
Layout with Stack View, Table View, and Collection View
Make School
 
PDF
iOS Layout Overview
Make School
 
PDF
Client Server Security with Flask and iOS
Make School
 
PDF
How to build quality software
Make School
 
Memory Management on iOS
Make School
 
Swift Objective-C Interop
Make School
 
Client Server Synchronization iOS
Make School
 
Dependency Management on iOS
Make School
 
Xcode Project Infrastructure
Make School
 
Localization and Accessibility on iOS
Make School
 
Distributing information on iOS
Make School
 
Swift 2 intro
Make School
 
Error Handling in Swift
Make School
 
Client Server Communication on iOS
Make School
 
Standard libraries on iOS
Make School
 
Make School 2017 - Mastering iOS Development
Make School
 
Multithreading on iOS
Make School
 
Advanced Core Data
Make School
 
Intro to Core Data
Make School
 
Persistence on iOS
Make School
 
Layout with Stack View, Table View, and Collection View
Make School
 
iOS Layout Overview
Make School
 
Client Server Security with Flask and iOS
Make School
 
How to build quality software
Make School
 
Ad

Recently uploaded (20)

PDF
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
PPTX
computer forensics encase emager app exp6 1.pptx
ssuser343e92
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PDF
Laboratory Workflows Digitalized and live in 90 days with Scifeon´s SAPPA P...
info969686
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PPTX
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PPTX
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
PPTX
Automatic_Iperf_Log_Result_Excel_visual_v2.pptx
Chen-Chih Lee
 
PDF
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
PDF
interacting-with-ai-2023---module-2---session-3---handout.pdf
cniclsh1
 
PPTX
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
PPTX
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
PDF
2025年 Linux 核心專題: 探討 sched_ext 及機器學習.pdf
Eric Chou
 
PPTX
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
PDF
From Chaos to Clarity: Mastering Analytics Governance in the Modern Enterprise
Wiiisdom
 
PPTX
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
PDF
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
 
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
computer forensics encase emager app exp6 1.pptx
ssuser343e92
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
Laboratory Workflows Digitalized and live in 90 days with Scifeon´s SAPPA P...
info969686
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
Automatic_Iperf_Log_Result_Excel_visual_v2.pptx
Chen-Chih Lee
 
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
interacting-with-ai-2023---module-2---session-3---handout.pdf
cniclsh1
 
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
2025年 Linux 核心專題: 探討 sched_ext 及機器學習.pdf
Eric Chou
 
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
From Chaos to Clarity: Mastering Analytics Governance in the Modern Enterprise
Wiiisdom
 
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
 

Intro to iOS Application Architecture

  • 3. AGENDA Goals of software architecture Design guidelines Practical tips
  • 5. GOALS OF SOFTWARE ARCHITECTURE Code is comprehensible for other developers Code can adopt to changing requirements Code can be shared within the project and throughout multiple projects
  • 6. THINK IN DOMAINS NOT IN OBJECTS
  • 10. SINGLE RESPONSIBILITY PRINCIPLE Avoid having many responsibilities within a single class Very important when implementing UIViewController subclasses Bad View Controller handles: Persistence, Business Logic, View Logic, etc.
  • 12. ENCAPSULATE Every component should know as little as possible about its surrounding components 
 → reduces dependencies between components How can this be accomplished?
 → small interfaces for communication
  • 13. ENCAPSULATE Add Trip View Controller Core Data Client startSavingNewTrip(newTrip) displayError(nameError) setNameOfTrip(“SF Trip”) disableSaveButton() Classes are poorly encapsulated and very dependent on 
 each other - very hard to change code in any of the two classes
  • 14. ENCAPSULATE Add Trip View Controller Core Data Client saveTrip(newTrip) saveErrorOccurred(error) Small communication interface 
 reduces dependencies!
  • 16. #1 AVOID THE MASSIVE VIEW CONTROLLER
  • 17. AVOID THE MASSIVE VIEW CONTROLLER Rule of thumb: A View Controller with > 300 lines is probably doing more than it should do
  • 18. THINGS A VIEW CONTROLLER SHOULD DO Listen to callbacks from the View → invoke methods on the model layer → send responses from model back to the view
  • 19. THINGS A VIEW CONTROLLER SHOULD NOT DO Construct complex network requests Construct complex database queries Take care of object serialization / deserialization
  • 21. DEFINE EXPRESSIVE APIS E.g. instead of exposing details of the network layer, provide functions with a simple interface:
 func fetchAllUsers(callback: [User] -> ())
 
 fetchAllUsers { users in print(users) }
  • 22. #3 USE VIEW OBJECTS
  • 23. USE VIEW OBJECTS View objects encapsulate multiple properties that are relevant for a type to be displayed by a custom view This is preferred over setting individual properties from outside the view
  • 24. USE VIEW OBJECTS class UserView: UIView { @IBOutlet var nameLabel: UILabel! @IBOutlet var profilePictureImageView: UIImageView! var user: User? { didSet { nameLabel.text = user?.name profilePictureImageView.image = user?.profilePicture } } } let userView = UserView() let currentUser = User() currentUser.name = "TestUser" userView.user = currentUser View encapsulates how an 
 object is displayed!
  • 25. USE VIEW OBJECTS class UserView: UIView { @IBOutlet var nameLabel: UILabel! @IBOutlet var profilePictureImageView: UIImageView! } let userView = UserView() let currentUser = User() currentUser.name = "TestUser" userView.nameLabel.text = currentUser.name userView.profilePictureImageView.image = currentUser.profilePicture Code that uses UserView now
 depends on its UI components.
 Violates encapsulation!
  • 26. #4 BE WARY OF INHERITANCE
  • 27. BE WARY OF INHERITANCE Base View Class Trip View You can only inherit one set of functionality You tend to inherit functionality that you don’t need More modular alternatives: Functions that can operate on relevant types 
 (using generics) Protocols & Protocol Extensions
  • 28. BE WARY OF INHERITANCE Base View Class Trip View More Specific Trip View Trip View Error
 Representable Restorable Presentable
  • 30. SUMMARY Divide code into logical domains Strive for each unit of code having a single responsibility Consider using protocols instead of inheritance Define narrow and expressive APIs that hide implementation details of other units of code and reduce dependencies between your units
  • 32. ADDITIONAL RESOURCES Talk: Refactor the Mega-Controller WWDC 2015: Protocol Oriented Programming WWDC 2014: Advanced Application Architecture Ray Wenderlich: Protocol Oriented programming