ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
MVx patterns in iOS
Back to 1970s - MVC
It was at the beginning
Apple's result
¡ñ Controller changes Model and update View.
Controller can have many views
¡ñ View represents information from the Model
¡ñ Model is a data/logic/rules
MVC - conclusion
¡ñ Drawbacks
¡ð The View and the Model in fact are separated, but the View and the
Controller are tightly coupled
¡ð Difficult to test and maintain
¡ð Cause a massive ViewController
¡ñ Benefits
¡ð Cocoa MVC is the best architectural pattern in terms of the speed
of the development
¡ð Everyone is familiar with this approach
MVP
¡ñ Passive view
¡ñ Supervising controller
MVP - passive view
¡ñ The Model is the data
¡ñ The View is a passive
interface that displays
data and routes events
to the Presenter
¡ñ The Presenter retrieves
data from the Model,
and formats it for display
in the View. UIKit
independent.
MVP - sequence diagram
MVP - supervising controller
The main difference from
a PassiveView MVP is
Data Binding
This version of pattern is
less popular because of
tight coupling between the
View and the Model
MVP - conclusion
¡ñ Drawbacks
¡ð Time consuming
¡ñ Benefits
¡ð The responsibilities are divided between components
¡ð Reusable components
¡ð Testability is excellent, we can test most of the business logic due
to the dumb View
MVVM
¡ñ The Model is the data
¡ñ The View represents the
data from ViewModel
¡ñ ViewModel knows about
the Model and
fetch/create/update a data
and notify the View about
changes. UIKit
independent.
MVVM - sequence diagram
MVVM - conclusion
¡ñ Drawbacks
¡ð Data binding between the View and the ViewModel can be
compicated
¡ñ Benefits
¡ð The ViewModel and the Model can be easily tested because are
independent of UIKit
¡ð The responsibilities divided between components
Code examples
You can find Xcode project with examples MVC, MVP and
MVVM on GitHub page:
https://github.com/voloshynslavik/MVx-Patterns-In-Swift

More Related Content

What's hot (20)

MVVM
MVVMMVVM
MVVM
Victor-Andrei Filimon
?
Mvvm basics
Mvvm basicsMvvm basics
Mvvm basics
anusha kadimi
?
²Ñ³Õ°ä¤â¤ä¤â¤ä»°
²Ñ³Õ°ä¤â¤ä¤â¤ä»°²Ñ³Õ°ä¤â¤ä¤â¤ä»°
²Ñ³Õ°ä¤â¤ä¤â¤ä»°
Tetsuya Kaneuchi
?
Introduction to mvc architecture
Introduction to mvc architectureIntroduction to mvc architecture
Introduction to mvc architecture
ravindraquicsolv
?
Acrhitecture deisign pattern_MVC_MVP_MVVM
Acrhitecture deisign pattern_MVC_MVP_MVVMAcrhitecture deisign pattern_MVC_MVP_MVVM
Acrhitecture deisign pattern_MVC_MVP_MVVM
Dong-Ho Lee
?
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
ivpol
?
iOS architecture patterns
iOS architecture patternsiOS architecture patterns
iOS architecture patterns
allanh0526
?
Modele mvcModele mvc
Modele mvc
Soulef riahi
?
Dot Net Core
Dot Net CoreDot Net Core
Dot Net Core
Amir Barylko
?
Model View Controller (MVC)
Model View Controller (MVC)Model View Controller (MVC)
Model View Controller (MVC)
Javier Antonio Humar¨¢n Pe?u?uri
?
MVC ppt presentation
MVC ppt presentationMVC ppt presentation
MVC ppt presentation
Bhavin Shah
?
MVVM presentation
MVVM presentationMVVM presentation
MVVM presentation
Inova LLC
?
A la d¨¦couverte de vue.jsA la d¨¦couverte de vue.js
A la d¨¦couverte de vue.js
Bruno Bonnin
?
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
Volkan Uzun
?
Asp.net MVC training session
Asp.net MVC training sessionAsp.net MVC training session
Asp.net MVC training session
Hrichi Mohamed
?
Spring MVC Framework
Spring MVC FrameworkSpring MVC Framework
Spring MVC Framework
H¨´ng Nguy?n Huy
?
MVC Framework
MVC FrameworkMVC Framework
MVC Framework
Ashton Feller
?
Spring mvc
Spring mvcSpring mvc
Spring mvc
Pravin Pundge
?
Clean architecture on android
Clean architecture on androidClean architecture on android
Clean architecture on android
Benjamin Cheng
?
ASP.NET MVC.
ASP.NET MVC.ASP.NET MVC.
ASP.NET MVC.
Ni
?
²Ñ³Õ°ä¤â¤ä¤â¤ä»°
²Ñ³Õ°ä¤â¤ä¤â¤ä»°²Ñ³Õ°ä¤â¤ä¤â¤ä»°
²Ñ³Õ°ä¤â¤ä¤â¤ä»°
Tetsuya Kaneuchi
?
Introduction to mvc architecture
Introduction to mvc architectureIntroduction to mvc architecture
Introduction to mvc architecture
ravindraquicsolv
?
Acrhitecture deisign pattern_MVC_MVP_MVVM
Acrhitecture deisign pattern_MVC_MVP_MVVMAcrhitecture deisign pattern_MVC_MVP_MVVM
Acrhitecture deisign pattern_MVC_MVP_MVVM
Dong-Ho Lee
?
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
ivpol
?
iOS architecture patterns
iOS architecture patternsiOS architecture patterns
iOS architecture patterns
allanh0526
?
Modele mvcModele mvc
Modele mvc
Soulef riahi
?
MVC ppt presentation
MVC ppt presentationMVC ppt presentation
MVC ppt presentation
Bhavin Shah
?
MVVM presentation
MVVM presentationMVVM presentation
MVVM presentation
Inova LLC
?
A la d¨¦couverte de vue.jsA la d¨¦couverte de vue.js
A la d¨¦couverte de vue.js
Bruno Bonnin
?
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
Volkan Uzun
?
Asp.net MVC training session
Asp.net MVC training sessionAsp.net MVC training session
Asp.net MVC training session
Hrichi Mohamed
?
Clean architecture on android
Clean architecture on androidClean architecture on android
Clean architecture on android
Benjamin Cheng
?
ASP.NET MVC.
ASP.NET MVC.ASP.NET MVC.
ASP.NET MVC.
Ni
?

Similar to MVx patterns in iOS (MVC, MVP, MVVM) (20)

MVC architecture in software programming for interactive apps
MVC architecture in software programming for interactive appsMVC architecture in software programming for interactive apps
MVC architecture in software programming for interactive apps
KotiTenali
?
§â§Ö§Ñ§Ý§Ú§Ú §Ú§ã§á§à§Ý§î§Ù§à§Ó§Ñ§ß§Ú§ñ Mv §Ó i os §â§Ñ§Ù§â§Ñ§Ò§à§ä§Ü§Ö
§â§Ö§Ñ§Ý§Ú§Ú §Ú§ã§á§à§Ý§î§Ù§à§Ó§Ñ§ß§Ú§ñ Mv §Ó i os §â§Ñ§Ù§â§Ñ§Ò§à§ä§Ü§Ö§â§Ö§Ñ§Ý§Ú§Ú §Ú§ã§á§à§Ý§î§Ù§à§Ó§Ñ§ß§Ú§ñ Mv §Ó i os §â§Ñ§Ù§â§Ñ§Ò§à§ä§Ü§Ö
§â§Ö§Ñ§Ý§Ú§Ú §Ú§ã§á§à§Ý§î§Ù§à§Ó§Ñ§ß§Ú§ñ Mv §Ó i os §â§Ñ§Ù§â§Ñ§Ò§à§ä§Ü§Ö
Provectus
?
Knockout js
Knockout jsKnockout js
Knockout js
Dr. Awase Khirni Syed
?
Mvc pattern and implementation in java fair
Mvc   pattern   and implementation   in   java fairMvc   pattern   and implementation   in   java fair
Mvc pattern and implementation in java fair
Tech_MX
?
Ios models
Ios modelsIos models
Ios models
JUDYFLAVIAB
?
Web engineering - MVC
Web engineering - MVCWeb engineering - MVC
Web engineering - MVC
Nosheen Qamar
?
Architectural Design & Patterns
Architectural Design&PatternsArchitectural Design&Patterns
Architectural Design & Patterns
Inocentshuja Ahmad
?
Model View Controller
Model View ControllerModel View Controller
Model View Controller
Madhukar Kumar
?
Session 5 : mvc - Gi¨¢o tr¨¬nh B¨¢ch Khoa Aptech
Session 5 : mvc  - Gi¨¢o tr¨¬nh B¨¢ch Khoa AptechSession 5 : mvc  - Gi¨¢o tr¨¬nh B¨¢ch Khoa Aptech
Session 5 : mvc - Gi¨¢o tr¨¬nh B¨¢ch Khoa Aptech
MasterCode.vn
?
MVVM and Prism
MVVM and PrismMVVM and Prism
MVVM and Prism
Bilal Ahmed
?
Ui design patterns
Ui design patternsUi design patterns
Ui design patterns
Jorge Ortiz
?
Mobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelinesMobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelines
Qamar Abbas
?
MVC
MVCMVC
MVC
Iman Mehmandoust
?
Interaction-Oriented Architecture.pptx
Interaction-Oriented Architecture.pptxInteraction-Oriented Architecture.pptx
Interaction-Oriented Architecture.pptx
Godwin Monserate
?
MVP Clean Architecture
MVP Clean  Architecture MVP Clean  Architecture
MVP Clean Architecture
Himanshu Dudhat
?
Model View Controller ext4
Model View Controller  ext4Model View Controller  ext4
Model View Controller ext4
Pankaj Avhad
?
MVC architecture
MVC architectureMVC architecture
MVC architecture
baabtra.com - No. 1 supplier of quality freshers
?
Mvc 130330091359-phpapp01
Mvc 130330091359-phpapp01Mvc 130330091359-phpapp01
Mvc 130330091359-phpapp01
Jennie Gajjar
?
software architecture
software architecturesoftware architecture
software architecture
arnav gupta
?
Mvc architecture
Mvc architectureMvc architecture
Mvc architecture
Surbhi Panhalkar
?
MVC architecture in software programming for interactive apps
MVC architecture in software programming for interactive appsMVC architecture in software programming for interactive apps
MVC architecture in software programming for interactive apps
KotiTenali
?
§â§Ö§Ñ§Ý§Ú§Ú §Ú§ã§á§à§Ý§î§Ù§à§Ó§Ñ§ß§Ú§ñ Mv §Ó i os §â§Ñ§Ù§â§Ñ§Ò§à§ä§Ü§Ö
§â§Ö§Ñ§Ý§Ú§Ú §Ú§ã§á§à§Ý§î§Ù§à§Ó§Ñ§ß§Ú§ñ Mv §Ó i os §â§Ñ§Ù§â§Ñ§Ò§à§ä§Ü§Ö§â§Ö§Ñ§Ý§Ú§Ú §Ú§ã§á§à§Ý§î§Ù§à§Ó§Ñ§ß§Ú§ñ Mv §Ó i os §â§Ñ§Ù§â§Ñ§Ò§à§ä§Ü§Ö
§â§Ö§Ñ§Ý§Ú§Ú §Ú§ã§á§à§Ý§î§Ù§à§Ó§Ñ§ß§Ú§ñ Mv §Ó i os §â§Ñ§Ù§â§Ñ§Ò§à§ä§Ü§Ö
Provectus
?
Mvc pattern and implementation in java fair
Mvc   pattern   and implementation   in   java fairMvc   pattern   and implementation   in   java fair
Mvc pattern and implementation in java fair
Tech_MX
?
Session 5 : mvc - Gi¨¢o tr¨¬nh B¨¢ch Khoa Aptech
Session 5 : mvc  - Gi¨¢o tr¨¬nh B¨¢ch Khoa AptechSession 5 : mvc  - Gi¨¢o tr¨¬nh B¨¢ch Khoa Aptech
Session 5 : mvc - Gi¨¢o tr¨¬nh B¨¢ch Khoa Aptech
MasterCode.vn
?
Mobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelinesMobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelines
Qamar Abbas
?
Interaction-Oriented Architecture.pptx
Interaction-Oriented Architecture.pptxInteraction-Oriented Architecture.pptx
Interaction-Oriented Architecture.pptx
Godwin Monserate
?
Model View Controller ext4
Model View Controller  ext4Model View Controller  ext4
Model View Controller ext4
Pankaj Avhad
?
Mvc 130330091359-phpapp01
Mvc 130330091359-phpapp01Mvc 130330091359-phpapp01
Mvc 130330091359-phpapp01
Jennie Gajjar
?
software architecture
software architecturesoftware architecture
software architecture
arnav gupta
?

Recently uploaded (20)

Airport Components Part2 ppt.pptx-Apron,Hangers,Terminal building
Airport Components Part2 ppt.pptx-Apron,Hangers,Terminal buildingAirport Components Part2 ppt.pptx-Apron,Hangers,Terminal building
Airport Components Part2 ppt.pptx-Apron,Hangers,Terminal building
Priyanka Dange
?
iso 45001 en 111111111111111111111111111
iso 45001 en 111111111111111111111111111iso 45001 en 111111111111111111111111111
iso 45001 en 111111111111111111111111111
ssuser3c947d
?
LA11-Case study of motherboard and internal components of motheroard.docx
LA11-Case study of motherboard and internal components of motheroard.docxLA11-Case study of motherboard and internal components of motheroard.docx
LA11-Case study of motherboard and internal components of motheroard.docx
VidyaAshokNemade
?
NFPA 70B & 70E Changes and Additions Webinar Presented By Fluke
NFPA 70B & 70E Changes and Additions Webinar Presented By FlukeNFPA 70B & 70E Changes and Additions Webinar Presented By Fluke
NFPA 70B & 70E Changes and Additions Webinar Presented By Fluke
Transcat
?
hyderabad ins tech and management cyber security
hyderabad ins tech and management cyber securityhyderabad ins tech and management cyber security
hyderabad ins tech and management cyber security
aramaky
?
CNC Technology Unit-5 for IV Year 24-25 MECH
CNC Technology Unit-5 for IV Year 24-25 MECHCNC Technology Unit-5 for IV Year 24-25 MECH
CNC Technology Unit-5 for IV Year 24-25 MECH
C Sai Kiran
?
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
NIT SILCHAR
?
Water Industry Process Automation & Control Monthly - April 2025
Water Industry Process Automation & Control Monthly - April 2025Water Industry Process Automation & Control Monthly - April 2025
Water Industry Process Automation & Control Monthly - April 2025
Water Industry Process Automation & Control
?
"Introduction to VLSI Design: Concepts and Applications"
"Introduction to VLSI Design: Concepts and Applications""Introduction to VLSI Design: Concepts and Applications"
"Introduction to VLSI Design: Concepts and Applications"
GtxDriver
?
Reinventando el CD_ Unificando Aplicaciones e Infraestructura con Crossplane-...
Reinventando el CD_ Unificando Aplicaciones e Infraestructura con Crossplane-...Reinventando el CD_ Unificando Aplicaciones e Infraestructura con Crossplane-...
Reinventando el CD_ Unificando Aplicaciones e Infraestructura con Crossplane-...
Alberto Lorenzo
?
Intro of Airport Engg..pptx-Definition of airport engineering and airport pla...
Intro of Airport Engg..pptx-Definition of airport engineering and airport pla...Intro of Airport Engg..pptx-Definition of airport engineering and airport pla...
Intro of Airport Engg..pptx-Definition of airport engineering and airport pla...
Priyanka Dange
?
Airport Components Part1 ppt.pptx-Site layout,RUNWAY,TAXIWAY,TAXILANE
Airport Components Part1 ppt.pptx-Site layout,RUNWAY,TAXIWAY,TAXILANEAirport Components Part1 ppt.pptx-Site layout,RUNWAY,TAXIWAY,TAXILANE
Airport Components Part1 ppt.pptx-Site layout,RUNWAY,TAXIWAY,TAXILANE
Priyanka Dange
?
M21 BUILDING INFORMATION MODELLING - BIM.pdf
M21  BUILDING INFORMATION MODELLING - BIM.pdfM21  BUILDING INFORMATION MODELLING - BIM.pdf
M21 BUILDING INFORMATION MODELLING - BIM.pdf
Ajaharuddin1
?
CNC Technology Unit-3 for IV Year 24-25 MECH
CNC Technology Unit-3 for IV Year 24-25 MECHCNC Technology Unit-3 for IV Year 24-25 MECH
CNC Technology Unit-3 for IV Year 24-25 MECH
C Sai Kiran
?
Virtual Power plants-Cleantech-Revolution
Virtual Power plants-Cleantech-RevolutionVirtual Power plants-Cleantech-Revolution
Virtual Power plants-Cleantech-Revolution
Ashoka Saket
?
Optimize AI Latency & Response Time with LLumo
Optimize AI Latency & Response Time with LLumoOptimize AI Latency & Response Time with LLumo
Optimize AI Latency & Response Time with LLumo
sgupta86
?
Electromechanical Engineering Portfolio RJH
Electromechanical Engineering Portfolio RJHElectromechanical Engineering Portfolio RJH
Electromechanical Engineering Portfolio RJH
rhoustonx1
?
Scalling Rails: The Journey to 200M Notifications
Scalling Rails: The Journey to 200M NotificationsScalling Rails: The Journey to 200M Notifications
Scalling Rails: The Journey to 200M Notifications
Gustavo Araujo
?
Supervised Learning Ensemble Techniques Machine Learning
Supervised Learning Ensemble Techniques Machine LearningSupervised Learning Ensemble Techniques Machine Learning
Supervised Learning Ensemble Techniques Machine Learning
ShivarkarSandip
?
CNC Technology Unit-1 for IV Year 24-25 MECH
CNC Technology Unit-1 for IV Year 24-25 MECHCNC Technology Unit-1 for IV Year 24-25 MECH
CNC Technology Unit-1 for IV Year 24-25 MECH
C Sai Kiran
?
Airport Components Part2 ppt.pptx-Apron,Hangers,Terminal building
Airport Components Part2 ppt.pptx-Apron,Hangers,Terminal buildingAirport Components Part2 ppt.pptx-Apron,Hangers,Terminal building
Airport Components Part2 ppt.pptx-Apron,Hangers,Terminal building
Priyanka Dange
?
iso 45001 en 111111111111111111111111111
iso 45001 en 111111111111111111111111111iso 45001 en 111111111111111111111111111
iso 45001 en 111111111111111111111111111
ssuser3c947d
?
LA11-Case study of motherboard and internal components of motheroard.docx
LA11-Case study of motherboard and internal components of motheroard.docxLA11-Case study of motherboard and internal components of motheroard.docx
LA11-Case study of motherboard and internal components of motheroard.docx
VidyaAshokNemade
?
NFPA 70B & 70E Changes and Additions Webinar Presented By Fluke
NFPA 70B & 70E Changes and Additions Webinar Presented By FlukeNFPA 70B & 70E Changes and Additions Webinar Presented By Fluke
NFPA 70B & 70E Changes and Additions Webinar Presented By Fluke
Transcat
?
hyderabad ins tech and management cyber security
hyderabad ins tech and management cyber securityhyderabad ins tech and management cyber security
hyderabad ins tech and management cyber security
aramaky
?
CNC Technology Unit-5 for IV Year 24-25 MECH
CNC Technology Unit-5 for IV Year 24-25 MECHCNC Technology Unit-5 for IV Year 24-25 MECH
CNC Technology Unit-5 for IV Year 24-25 MECH
C Sai Kiran
?
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
NIT SILCHAR
?
"Introduction to VLSI Design: Concepts and Applications"
"Introduction to VLSI Design: Concepts and Applications""Introduction to VLSI Design: Concepts and Applications"
"Introduction to VLSI Design: Concepts and Applications"
GtxDriver
?
Reinventando el CD_ Unificando Aplicaciones e Infraestructura con Crossplane-...
Reinventando el CD_ Unificando Aplicaciones e Infraestructura con Crossplane-...Reinventando el CD_ Unificando Aplicaciones e Infraestructura con Crossplane-...
Reinventando el CD_ Unificando Aplicaciones e Infraestructura con Crossplane-...
Alberto Lorenzo
?
Intro of Airport Engg..pptx-Definition of airport engineering and airport pla...
Intro of Airport Engg..pptx-Definition of airport engineering and airport pla...Intro of Airport Engg..pptx-Definition of airport engineering and airport pla...
Intro of Airport Engg..pptx-Definition of airport engineering and airport pla...
Priyanka Dange
?
Airport Components Part1 ppt.pptx-Site layout,RUNWAY,TAXIWAY,TAXILANE
Airport Components Part1 ppt.pptx-Site layout,RUNWAY,TAXIWAY,TAXILANEAirport Components Part1 ppt.pptx-Site layout,RUNWAY,TAXIWAY,TAXILANE
Airport Components Part1 ppt.pptx-Site layout,RUNWAY,TAXIWAY,TAXILANE
Priyanka Dange
?
M21 BUILDING INFORMATION MODELLING - BIM.pdf
M21  BUILDING INFORMATION MODELLING - BIM.pdfM21  BUILDING INFORMATION MODELLING - BIM.pdf
M21 BUILDING INFORMATION MODELLING - BIM.pdf
Ajaharuddin1
?
CNC Technology Unit-3 for IV Year 24-25 MECH
CNC Technology Unit-3 for IV Year 24-25 MECHCNC Technology Unit-3 for IV Year 24-25 MECH
CNC Technology Unit-3 for IV Year 24-25 MECH
C Sai Kiran
?
Virtual Power plants-Cleantech-Revolution
Virtual Power plants-Cleantech-RevolutionVirtual Power plants-Cleantech-Revolution
Virtual Power plants-Cleantech-Revolution
Ashoka Saket
?
Optimize AI Latency & Response Time with LLumo
Optimize AI Latency & Response Time with LLumoOptimize AI Latency & Response Time with LLumo
Optimize AI Latency & Response Time with LLumo
sgupta86
?
Electromechanical Engineering Portfolio RJH
Electromechanical Engineering Portfolio RJHElectromechanical Engineering Portfolio RJH
Electromechanical Engineering Portfolio RJH
rhoustonx1
?
Scalling Rails: The Journey to 200M Notifications
Scalling Rails: The Journey to 200M NotificationsScalling Rails: The Journey to 200M Notifications
Scalling Rails: The Journey to 200M Notifications
Gustavo Araujo
?
Supervised Learning Ensemble Techniques Machine Learning
Supervised Learning Ensemble Techniques Machine LearningSupervised Learning Ensemble Techniques Machine Learning
Supervised Learning Ensemble Techniques Machine Learning
ShivarkarSandip
?
CNC Technology Unit-1 for IV Year 24-25 MECH
CNC Technology Unit-1 for IV Year 24-25 MECHCNC Technology Unit-1 for IV Year 24-25 MECH
CNC Technology Unit-1 for IV Year 24-25 MECH
C Sai Kiran
?

MVx patterns in iOS (MVC, MVP, MVVM)

  • 2. Back to 1970s - MVC It was at the beginning Apple's result ¡ñ Controller changes Model and update View. Controller can have many views ¡ñ View represents information from the Model ¡ñ Model is a data/logic/rules
  • 3. MVC - conclusion ¡ñ Drawbacks ¡ð The View and the Model in fact are separated, but the View and the Controller are tightly coupled ¡ð Difficult to test and maintain ¡ð Cause a massive ViewController ¡ñ Benefits ¡ð Cocoa MVC is the best architectural pattern in terms of the speed of the development ¡ð Everyone is familiar with this approach
  • 4. MVP ¡ñ Passive view ¡ñ Supervising controller
  • 5. MVP - passive view ¡ñ The Model is the data ¡ñ The View is a passive interface that displays data and routes events to the Presenter ¡ñ The Presenter retrieves data from the Model, and formats it for display in the View. UIKit independent.
  • 6. MVP - sequence diagram
  • 7. MVP - supervising controller The main difference from a PassiveView MVP is Data Binding This version of pattern is less popular because of tight coupling between the View and the Model
  • 8. MVP - conclusion ¡ñ Drawbacks ¡ð Time consuming ¡ñ Benefits ¡ð The responsibilities are divided between components ¡ð Reusable components ¡ð Testability is excellent, we can test most of the business logic due to the dumb View
  • 9. MVVM ¡ñ The Model is the data ¡ñ The View represents the data from ViewModel ¡ñ ViewModel knows about the Model and fetch/create/update a data and notify the View about changes. UIKit independent.
  • 10. MVVM - sequence diagram
  • 11. MVVM - conclusion ¡ñ Drawbacks ¡ð Data binding between the View and the ViewModel can be compicated ¡ñ Benefits ¡ð The ViewModel and the Model can be easily tested because are independent of UIKit ¡ð The responsibilities divided between components
  • 12. Code examples You can find Xcode project with examples MVC, MVP and MVVM on GitHub page: https://github.com/voloshynslavik/MVx-Patterns-In-Swift

Editor's Notes

  • #2: Today we will talk about three most most popular architecture patterns in iOS MVC MVP and MVVM. First of all we will look at structure and then will check how does it look in code. I wrote simple one screen application that downloads photos and displays them in UICollectionView.
  • #3: So, let's start from the oldest one - MVC Here we have 3 main components Controller View and Model In this case, the View is stateless. It is simply rendered by the Controller once the Model is changed. What did Apple? They combined View and Controller into one entity that calls viewcontoller let's see how does it look in example
  • #4: Classical MVC is usuful but not in iOS, because it causes big amount of problems. To be honest I'm not sure that we can call this MVC that provides us Apple. This approach is the main reason why we have code that can't be covered by tests and a MassiveViewController. It's difficult to belive in it, but there are even benefits. At least everyone knows how to write a code in this style and this pattern is the best one if you need quickly check something, for example proof of concept or prototype.
  • #5: This pattern is more powerful than the previous one. MPV has 2 different modifications: first Passive view and second supervising controller. Let's start from Passive view and then check the differences between them
  • #6: The Model is the same as in MVC but Presenter and a View are completely different The presenter is the cental part that knows about Data and View. Between presenter and model there is typical connection. Presenter has a link on the model and model notifies about changes via calback or delegates But There is an interesting connection between view and presenter. Actually this part between view-presenter contection was the most confusing for me. They have a link on each other. It means thas one of them should be declared as a weak reference.
  • #7: Here you can see how it works User, for example, press button and View cathes this event Then redirect the event to presenter. Presenter handles it somehow, do something with model and updates the View at the end
  • #8: As you can see this version of MVP pattern looks the same as the previous one. But here we see data bindling with a model.
  • #9: This pattern is quite complex to understand at the beginning and probably it's the most time consuming pattern from an MV* generation. But in the end you will get the flexible structure that can be easy covered by tests. The reusability is marvellous. You can reuse everything. Let's imagine that the same screen with CollectionView that represents list of images from Instagram, then we need to simply add new Presenter that downloads photos from another source. And vise-versa if we want to add new new screen with table view instead of collection view, or just show single image. You need just change a view, but presenter can be the same.
  • #10: This pattern is more familiar us then previous 2. The view has a reference on view model, and viiew model has a reference on the model. One important think is that viewmodel is uikit independent. It means that we can't use classes from UIKIt framework.
  • #11: The quality of image is not the best, but I hope that you see what is there so, how does it work in general? for example user clicks on the button, view catch this event and asks ViewModel to handle it. then view model update model and notifies the View about result
  • #12: And conclusion If talk about bad side of viewmodel it can be data binding. It is easy to track changes in viewmodel if you have only one object, but if track for example 5 and everyone has own callback or delegate it's became messy but viewmodel pattern is good in that sense that responsibilities are devided between components and these components can be easily tested