SlideShare a Scribd company logo
1 of 27
iOS Architecture Patterns
Hoang Hai Hung
Outline
1. MV(x)
2. VIPER
3. VIP (Clean Swift)
4. Redux
5. Demo
Write less code, get more done
What is a good architecture ?
1. Distributions : Balanced distribution of responsibilities among entities
with strict roles.
2. Testability usually comes from the first feature
3. Ease of use and a low maintenance cost.
...
What is a good architecture ?
MVC - MVP - MVVM
Models— domain data or a data access layer which manipulates the data
Views— responsible for the presentation layer (GUI), for iOS is everything
starting with ‘UI’ prefix.
Controller/Presenter/ViewModel— the glue or the mediator between the
Model and the View, responsible for altering the Model by reacting to
the user’s actions performed on the View and updating the View with
changes from the Model.
MVC
Apple's MVC
Massive View Controller
Sample code:
https://gist.github.com/BohdanOrlov/6e87048a0db79ceecce8#file-mvc-swift
Lighter view controllers
Separate Out Data Source and Other Protocols
Move Domain Logic into the Model
Creating the Store Class
Move Web Service Logic to the Model Layer
Design patterns
...
MVP
Sample code:
https://gist.github.com/BohdanOrlov/dd0bc1ba235b902a085f#file-mvp-swift
MVVM
Sample code:
https://gist.github.com/BohdanOrlov/bdb64ae4ca83a2fca3af#file-mvvm-swift
VIPER
Sample code:
https://gist.github.com/BohdanOrlov/ae3158cad9b7e75a8099#file-viper-swift
Clean Swift
What is Redux ?
Redux is a predictable state container for JavaScript apps.
Redux
What is ReSwift ?
ReSwift is a Redux-like implementation of the unidirectional data flow
architecture in Swift.
Github : https://github.com/ReSwift/ReSwift
Documentation : http://reswift.github.io/ReSwift/master/
Redux - 3 principles
1. Single source of truth.
2. State is read-only.
3. Changes are made with pure functions.
State
The application state is defined in a single data structure which should be a
struct. This struct can have other structs as members, that allows you to add
different sub-states as your app grows.
The state struct should store your entire application state, that includes the
UI state, the navigation state and the state of your model layer.
struct AppState: StateType {
var counter: Int = 0
var navigationState = NavigationState()
}
Actions
Actions are used to express intended state changes. Actions don’t contain
functions, instead they provide information about the intended state change,
e.g. which user should be deleted.
struct LikePostAction: Action {
let post: Post
let userLikingPost: User
}
Reducers
Reducers are the only place in which you should modify application state!
Reducers take the current application state and an action and return the new
transformed application state.
struct AppReducer: Reducer {
func handleAction(action: Action, state: State?) -> State {
return State(
navigationState: NavigationReducer.handleAction(action, state: state?.navigationState),
authenticationState: authenticationReducer(state?.authenticationState, action: action),
repositories: repositoriesReducer(state?.repositories, action: action),
bookmarks: bookmarksReducer(state?.bookmarks, action: action))
}
}
Reducers
func authenticationReducer(state: AuthenticationState?, action: Action) -> AuthenticationState {
var state = state ?? initialAuthenticationState()
switch action {
case _ as SwiftFlowInit:
break
case let action as SetOAuthURL:
state.oAuthURL = action.oAuthUrl
case let action as UpdateLoggedInState:
state.loggedInState = action.loggedInState
default:
break
}
return state
}
Store Subscriber
Receiving state updates from a store
Whenever the store updates its state it will notify all subscribers by calling
the newState method on themprotocol StoreSubscriber {
func newState(state: StoreSubscriberStateType)
}
store.subscribe(self) { state in
state.repositories
}
Action Creator
ActionCreators to perform a conditional dispatch.
An ActionCreator takes the current application state, and a reference to a
store and might or might not return an Action.
typealias ActionCreator = (state: State, store: StoreType) -> Action?
Middleware
Middleware allows developers to provide extensions that wrap the dispatch
function.
let loggingMiddleware: Middleware = { dispatch, getState in
return { next in
return { action in
// perform middleware logic
print(action)
// call next middleware
return next(action)
}
}
}
Store(reducer: reducer, appState: TestStringAppState(), middleware: [loggingMiddleware,
secondMiddleware])
Why Redux ?
Better state management
Visible
Designed
Explicit
Type system enforced
Testable transitions
Summary
References
https://medium.com/ios-os-x-development/ios-architecture-patterns-
ecba4c38de52
https://swifting.io/blog/2016/09/07/architecture-wars-a-new-hope/
http://clean-swift.com/clean-swift-ios-architecture/
https://realm.io/news/benji-encz-unidirectional-data-flow-swift/
THANK YOU !

More Related Content

What's hot

What's hot (20)

Introduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoCIntroduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoC
 
Spring boot
Spring bootSpring boot
Spring boot
 
Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
 
Design Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVMDesign Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVM
 
Java 9/10/11 - What's new and why you should upgrade
Java 9/10/11 - What's new and why you should upgradeJava 9/10/11 - What's new and why you should upgrade
Java 9/10/11 - What's new and why you should upgrade
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
 
React workshop
React workshopReact workshop
React workshop
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Webpack Introduction
Webpack IntroductionWebpack Introduction
Webpack Introduction
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Introduction to fragments in android
Introduction to fragments in androidIntroduction to fragments in android
Introduction to fragments in android
 
Spring AOP in Nutshell
Spring AOP in Nutshell Spring AOP in Nutshell
Spring AOP in Nutshell
 
Spring ppt
Spring pptSpring ppt
Spring ppt
 
What is component in reactjs
What is component in reactjsWhat is component in reactjs
What is component in reactjs
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Preview
 
Spring framework Introduction
Spring framework IntroductionSpring framework Introduction
Spring framework Introduction
 
Spring Core
Spring CoreSpring Core
Spring Core
 
React Class Components vs Functional Components: Which is Better?
React Class Components vs Functional Components: Which is Better?React Class Components vs Functional Components: Which is Better?
React Class Components vs Functional Components: Which is Better?
 

Similar to iOS Architectures

LearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLLearningMVCWithLINQToSQL
LearningMVCWithLINQToSQL
Akhil Mittal
 
Windows phone 7 series
Windows phone 7 seriesWindows phone 7 series
Windows phone 7 series
openbala
 

Similar to iOS Architectures (20)

Understanding angular js
Understanding angular jsUnderstanding angular js
Understanding angular js
 
Lec 4.ppt
Lec 4.pptLec 4.ppt
Lec 4.ppt
 
Compose Camp by GDSC NSUT
Compose Camp by GDSC NSUTCompose Camp by GDSC NSUT
Compose Camp by GDSC NSUT
 
downloads_introduction to redux.pptx
downloads_introduction to redux.pptxdownloads_introduction to redux.pptx
downloads_introduction to redux.pptx
 
React and MobX: A Truly Reactive App
React and MobX:  A Truly Reactive AppReact and MobX:  A Truly Reactive App
React and MobX: A Truly Reactive App
 
[@NaukriEngineering] Flux Architecture
[@NaukriEngineering] Flux Architecture[@NaukriEngineering] Flux Architecture
[@NaukriEngineering] Flux Architecture
 
What 100M downloads taught us about iOS architectures
What 100M downloads taught us about iOS architecturesWhat 100M downloads taught us about iOS architectures
What 100M downloads taught us about iOS architectures
 
Ios development 2
Ios development 2Ios development 2
Ios development 2
 
Crafted Design - ITAKE 2014
Crafted Design - ITAKE 2014Crafted Design - ITAKE 2014
Crafted Design - ITAKE 2014
 
MVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVCMVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVC
 
LearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLLearningMVCWithLINQToSQL
LearningMVCWithLINQToSQL
 
an Introduction to Redux
an Introduction to Reduxan Introduction to Redux
an Introduction to Redux
 
Reducers+flux=redux
Reducers+flux=reduxReducers+flux=redux
Reducers+flux=redux
 
Redux
ReduxRedux
Redux
 
Getting started with Redux js
Getting started with Redux jsGetting started with Redux js
Getting started with Redux js
 
Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...
Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...
Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...
 
From User Action to Framework Reaction
From User Action to Framework ReactionFrom User Action to Framework Reaction
From User Action to Framework Reaction
 
Windows phone 7 series
Windows phone 7 seriesWindows phone 7 series
Windows phone 7 series
 
Client Side MVC & Angular
Client Side MVC & AngularClient Side MVC & Angular
Client Side MVC & Angular
 
Jinal desai .net
Jinal desai .netJinal desai .net
Jinal desai .net
 

Recently uploaded

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Recently uploaded (20)

Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 

iOS Architectures

Editor's Notes

  1. state, noun the particular condition that someone or something is in at a specific time. Although state changes over time, the state at any particular point in time is fixed.
  2. What information do we need to provide to it? And what actions does it produce?
  3. each component and store item is mockable, replacable, and testable in isolation. Both outside of the store, AND outside of view controllers.