SlideShare une entreprise Scribd logo
1  sur  22
Télécharger pour lire hors ligne
iOS App Architectures 
VIPER 
Rajat Datta 
CocoaCoder
What is the Problem? 
• Massive View Controllers 
• Model objects (Core Data) are typically quite simple 
• Views are combinations of UIKit components 
• do not have access to models 
• Only interaction with Controllers is via IBActions 
• View Controllers get everything else!
• What goes into View Controllers? 
• Data sources for Views (UITableView 
DataSource) 
• Business Logic 
• Application flow 
• transition between view controllers 
• VIPER is one proposal for a different app structure.
References 
• WWDC 2014 video: Advanced User Interfaces with 
Collection Views 
• Viper (MutualMobile): http://www.objc.io/issue-13/viper.html 
• MVVM Pattern from Microsoft: http://msdn.microsoft.com/en-us/ 
library/hh848246.aspx 
• The Clean Architecture (Uncle Bob): http://blog.8thlight.com/ 
uncle-bob/2012/08/13/the-clean-architecture.html 
• For the academically oriented: Object-Oriented Software 
Construction by Bertrand Meyer
• Lighter weight articles: 
• Clean Table View Code: http://www.objc.io/ 
issue-1/table-views.html 
• Lighter View Controllers: http://www.objc.io/ 
issue-1/lighter-view-controllers.html
VIPER 
• V(iew) I(nteractor) P(resenter) E(ntity) R(outer) 
View Presenter Interactor 
Entity 
Entity 
Wireframe 
Data Store
Views 
• UIKit components (UILabel, UITableView, …) 
• Presents a public interface that can be used to drive the UI 
• Views are completely passive; they don’t ask for the data to be shown. 
• implemented as public methods (ie. showName:(NSString *)name) 
• Defines an event interface triggered by IBActions, gestures 
• implemented as @protocol methods 
• ie. - (void)addEventAction:(id)sender; 
• The View Controller implements these two interfaces
Presenter (PONSO) 
• Drives the UI using the View public and event interfaces 
• Sends requests to the Interactor 
• with data entered in the View 
• for data to be presented in the View 
• Data are simple models, not entities 
• mostly read/only; no business logic can be applied 
• absolutely no notion of persistence is applied to these data models 
• Sends requests to the Wireframe for UI transitions 
• ie. for Add action, request the Wireframe to transition to Add View.
• Presenter can be a number of related objects 
• View:showName: method with NSString * 
• View:showTable: method with DataSource object 
• object is owned by Presenter
Wireframe (PONSO) 
• Owns the UIWindow, UINavigationController and all 
UIViewControllers 
• Presents an action interface for the Presenter 
• Responsible for transition animations. 
• Can work with Storyboards 
• for more complex flows 
• use Storyboard IDs and instantiate in code
Interactor (PONSO) 
• Each Interactor represents a single use-case in the app 
• All business logic is contained in the Interactor 
• Totally independent of UI, and can/should be covered by 
test cases. 
• This is where the core of all application dependencies 
will be found. 
• Fetches Entities from the Data Store 
• Passes and receives Models from the Presenter
Entities (PONSO) 
• Created by the Data Store 
• Object contents are modified by the Interactor 
• Is not a managed object. Entities do not know how 
to persist themselves. 
• Just data structures. App dependent logic should 
be in an Interactor.
Data Store 
• Responsible for presenting Entities to the Interactor 
• All persistence decisions are made here. 
• Can be replaced by a test double (mock). 
• Can be independently tested.
Demo App 
• Journal App 
• Journal Entry 
• Date and Time 
• Text 
• Last edit Date and Time 
• Use Cases 
• Add Journal Entry 
• Show Journal Entries 
• Edit an existing Journal Entry 
• Persistence 
• Core Data 
• Cloudkit?
Views 
• List View 
• Presenter starts the view with a datasource containing list of 
entries 
• from date, to date fields 
• when set, calls back via protocol method to the Presenter, 
which presents the view with a new datasource. 
• Edit Action (gesture on Table View?) 
• call back via protocol method to the Presenter, along with 
which journal entry selected. 
• Add Action (button?) 
• call back via protocol method to the Presenter.
Presenter 
• Initially, call Interactor and fetch journal entries for last 30 
days 
• Call View:showJournalList: with datasource containing 
list of journal entries; 
• callback from view with from and to dates; fetch data 
from Interactor and call View:showJournalList with that list 
• callback from view with edit action and journal entry; call 
to Wireframe to switch UI to Edit mode; 
• callback from view with add action; call to wireframe to 
switch UI to Add mode.
Interactor 
• For View Action 
• method to fetch all journal articles for last 30 days; also 
returns from date, to date 
• method which, given from date, to date, returns the list of 
journal entries within that time (inclusive). 
• For Add action 
• method which, given a date and time, returns a new, empty, 
journal entry 
• contains only the id for the entry (unix timestamp) 
• method which, given id and journal entry, calls the data store 
to save a new journal entry.
Entity 
• Data structure that Interactor passes along to the Data 
Store and back; 
• id (unix timestamp) for the journal entry. This is 
expected to be unique. 
• text: NSAttributedString 
• to be complete, should support images and formatting 
information. 
• last edit time. 
• In this case, this can also be the model 
• shared between the Interactor and the Presenter.
Wireframe 
• Switch to List View 
• Switch to Edit View 
• Switch to Add View
Data Store 
• in DataStore:init method, setup the Core Data sqlite 
store 
• DataStore:newJournalEntry 
• DataStore:fetchJournalEntriesFromDate:toDate: 
• DataStore:changedJournalEntry:
Edge Cases 
• Out of band information 
• network access status; simple case 
• Push notification informs app of new information 
• overlay Presenter, on top of existing Presenter 
• overlay Presenter can ask Wireframe to change 
the UI. 
• Presenter can offer method that puts a Presenter 
to sleep 
• For games, stop the game clock.
Flow Controllers 
• Reference: http://albertodebortoli.github.io/blog/ 
2014/09/03/flow-controllers-on-ios-for-a-better-navigation- 
control/ 
• Flow Controllers manage navigation control 
• are passed along from view controller to view 
controller 
• are initialized with the navigation controller instance 
• Basically, these are Presenter and Wireframe in one. 
• What about Storyboards?

Contenu connexe

Tendances

Observer design pattern
Observer design patternObserver design pattern
Observer design pattern
Sara Torkey
 
Introduction to hibernate
Introduction to hibernateIntroduction to hibernate
Introduction to hibernate
hr1383
 

Tendances (20)

Observer design pattern
Observer design patternObserver design pattern
Observer design pattern
 
MVC Framework
MVC FrameworkMVC Framework
MVC Framework
 
iOS architecture patterns
iOS architecture patternsiOS architecture patterns
iOS architecture patterns
 
Framework laravel
Framework laravelFramework laravel
Framework laravel
 
Spring User Guide
Spring User GuideSpring User Guide
Spring User Guide
 
Software Engineering - chp5- software architecture
Software Engineering - chp5- software architectureSoftware Engineering - chp5- software architecture
Software Engineering - chp5- software architecture
 
Introduction to Struts 1.3
Introduction to Struts 1.3Introduction to Struts 1.3
Introduction to Struts 1.3
 
Building blocks of Angular
Building blocks of AngularBuilding blocks of Angular
Building blocks of Angular
 
React workshop
React workshopReact workshop
React workshop
 
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of ControlJava Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
 
Why MVC?
Why MVC?Why MVC?
Why MVC?
 
Ngrx slides
Ngrx slidesNgrx slides
Ngrx slides
 
Clean Architecture Essentials - Stockholm Software Craftsmanship
Clean Architecture Essentials - Stockholm Software CraftsmanshipClean Architecture Essentials - Stockholm Software Craftsmanship
Clean Architecture Essentials - Stockholm Software Craftsmanship
 
Introduction to hibernate
Introduction to hibernateIntroduction to hibernate
Introduction to hibernate
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
 
SOLID Principles and The Clean Architecture
SOLID Principles and The Clean ArchitectureSOLID Principles and The Clean Architecture
SOLID Principles and The Clean Architecture
 
Spring MVC Framework
Spring MVC FrameworkSpring MVC Framework
Spring MVC Framework
 
Flux architecture
Flux architectureFlux architecture
Flux architecture
 
An introduction to React.js
An introduction to React.jsAn introduction to React.js
An introduction to React.js
 
Model view controller (mvc)
Model view controller (mvc)Model view controller (mvc)
Model view controller (mvc)
 

En vedette

iOS Architecture
iOS ArchitectureiOS Architecture
iOS Architecture
Jacky Lian
 

En vedette (20)

From mvc to viper
From mvc to viperFrom mvc to viper
From mvc to viper
 
VIPER - Design Pattern
VIPER - Design PatternVIPER - Design Pattern
VIPER - Design Pattern
 
Introduction to VIPER Architecture
Introduction to VIPER ArchitectureIntroduction to VIPER Architecture
Introduction to VIPER Architecture
 
Rambler.iOS #5: VIPER и Swift
Rambler.iOS #5: VIPER и SwiftRambler.iOS #5: VIPER и Swift
Rambler.iOS #5: VIPER и Swift
 
Break the monolith with (B)VIPER Modules
Break the monolith with (B)VIPER ModulesBreak the monolith with (B)VIPER Modules
Break the monolith with (B)VIPER Modules
 
[SIP 2015] iOS Proposal: VIPER
[SIP 2015] iOS Proposal: VIPER[SIP 2015] iOS Proposal: VIPER
[SIP 2015] iOS Proposal: VIPER
 
Rambler.iOS #5: VIPER a la Rambler
Rambler.iOS #5: VIPER a la RamblerRambler.iOS #5: VIPER a la Rambler
Rambler.iOS #5: VIPER a la Rambler
 
Viper - чистая архитектура iOS-приложения (И. Чирков)
Viper - чистая архитектура iOS-приложения (И. Чирков)Viper - чистая архитектура iOS-приложения (И. Чирков)
Viper - чистая архитектура iOS-приложения (И. Чирков)
 
Clean architecture workshop
Clean architecture workshopClean architecture workshop
Clean architecture workshop
 
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOSSoftware architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
 
iOS advanced architecture workshop 3h edition
iOS advanced architecture workshop 3h editioniOS advanced architecture workshop 3h edition
iOS advanced architecture workshop 3h edition
 
iOS Architecture
iOS ArchitectureiOS Architecture
iOS Architecture
 
Viper
ViperViper
Viper
 
«ReactiveCocoa и MVVM» — Николай Касьянов, SoftWear
«ReactiveCocoa и MVVM» — Николай Касьянов, SoftWear«ReactiveCocoa и MVVM» — Николай Касьянов, SoftWear
«ReactiveCocoa и MVVM» — Николай Касьянов, SoftWear
 
iOS Viper architecture for CocoaHeadsBY (RU)
iOS Viper architecture for CocoaHeadsBY (RU)iOS Viper architecture for CocoaHeadsBY (RU)
iOS Viper architecture for CocoaHeadsBY (RU)
 
Rambler.iOS #5: Генерамба и прочие аспекты кодогенерации в VIPER
Rambler.iOS #5: Генерамба и прочие аспекты кодогенерации в VIPERRambler.iOS #5: Генерамба и прочие аспекты кодогенерации в VIPER
Rambler.iOS #5: Генерамба и прочие аспекты кодогенерации в VIPER
 
An (highly elementary) introduction to VIPER
An (highly elementary) introduction to VIPERAn (highly elementary) introduction to VIPER
An (highly elementary) introduction to VIPER
 
Infinum iOS Talks #2 - VIPER for everybody by Damjan Vujaklija
Infinum iOS Talks #2 - VIPER for everybody by Damjan VujaklijaInfinum iOS Talks #2 - VIPER for everybody by Damjan Vujaklija
Infinum iOS Talks #2 - VIPER for everybody by Damjan Vujaklija
 
ReactiveCocoa: делаем отзывчивое приложение (П. Руденко)
ReactiveCocoa: делаем отзывчивое приложение (П. Руденко)ReactiveCocoa: делаем отзывчивое приложение (П. Руденко)
ReactiveCocoa: делаем отзывчивое приложение (П. Руденко)
 
Rambler.iOS #5: Переходы и передача данных между VIPER модулями
Rambler.iOS #5: Переходы и передача данных между VIPER модулямиRambler.iOS #5: Переходы и передача данных между VIPER модулями
Rambler.iOS #5: Переходы и передача данных между VIPER модулями
 

Similaire à iOS viper presentation

Thesis Defence: A Model Driven Architecture for the Web of Things
Thesis Defence: A Model Driven Architecture for the Web of ThingsThesis Defence: A Model Driven Architecture for the Web of Things
Thesis Defence: A Model Driven Architecture for the Web of Things
Andreas Ruppen
 

Similaire à iOS viper presentation (20)

Azure Application insights - An Introduction
Azure Application insights - An IntroductionAzure Application insights - An Introduction
Azure Application insights - An Introduction
 
ASP.NET MVC 2.0
ASP.NET MVC 2.0ASP.NET MVC 2.0
ASP.NET MVC 2.0
 
Software design with Domain-driven design
Software design with Domain-driven design Software design with Domain-driven design
Software design with Domain-driven design
 
Group meeting: Identifying Information Disclosure in Web Applications with Re...
Group meeting: Identifying Information Disclosure in Web Applications with Re...Group meeting: Identifying Information Disclosure in Web Applications with Re...
Group meeting: Identifying Information Disclosure in Web Applications with Re...
 
Asp.Net MVC 5 in Arabic
Asp.Net MVC 5 in ArabicAsp.Net MVC 5 in Arabic
Asp.Net MVC 5 in Arabic
 
CQRS and Event Sourcing for IoT applications
CQRS and Event Sourcing for IoT applicationsCQRS and Event Sourcing for IoT applications
CQRS and Event Sourcing for IoT applications
 
From MEAN to the MERN Stack
From MEAN to the MERN StackFrom MEAN to the MERN Stack
From MEAN to the MERN Stack
 
Deep Dive into Azure Data Factory v2
Deep Dive into Azure Data Factory v2Deep Dive into Azure Data Factory v2
Deep Dive into Azure Data Factory v2
 
Deep-Dive to Application Insights
Deep-Dive to Application Insights Deep-Dive to Application Insights
Deep-Dive to Application Insights
 
Getting started with MVC 5 and Visual Studio 2013
Getting started with MVC 5 and Visual Studio 2013Getting started with MVC 5 and Visual Studio 2013
Getting started with MVC 5 and Visual Studio 2013
 
.NET Fest 2019. Halil Ibrahim Kalkan. Implementing Domain Driven Design
.NET Fest 2019. Halil Ibrahim Kalkan. Implementing Domain Driven Design.NET Fest 2019. Halil Ibrahim Kalkan. Implementing Domain Driven Design
.NET Fest 2019. Halil Ibrahim Kalkan. Implementing Domain Driven Design
 
WoTKit: a Lightweight Toolkit for the Web of Things
WoTKit: a Lightweight Toolkit for the Web of ThingsWoTKit: a Lightweight Toolkit for the Web of Things
WoTKit: a Lightweight Toolkit for the Web of Things
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & Databases
 
A Model-Driven, Component Generation Approach for the Web of Things
A Model-Driven, Component Generation Approach for the Web of ThingsA Model-Driven, Component Generation Approach for the Web of Things
A Model-Driven, Component Generation Approach for the Web of Things
 
Thesis Defence: A Model Driven Architecture for the Web of Things
Thesis Defence: A Model Driven Architecture for the Web of ThingsThesis Defence: A Model Driven Architecture for the Web of Things
Thesis Defence: A Model Driven Architecture for the Web of Things
 
Data Vault Automation at the Bijenkorf
Data Vault Automation at the BijenkorfData Vault Automation at the Bijenkorf
Data Vault Automation at the Bijenkorf
 
Streams API (Web Engines Hackfest 2015)
Streams API (Web Engines Hackfest 2015)Streams API (Web Engines Hackfest 2015)
Streams API (Web Engines Hackfest 2015)
 
Azure Digital Twins 2.0
Azure Digital Twins 2.0Azure Digital Twins 2.0
Azure Digital Twins 2.0
 
Getting Started with Innoslate
Getting Started with InnoslateGetting Started with Innoslate
Getting Started with Innoslate
 
iOS (7) Workshop
iOS (7) WorkshopiOS (7) Workshop
iOS (7) Workshop
 

Dernier

%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
+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
 

Dernier (20)

%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
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
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
+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...
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 

iOS viper presentation

  • 1. iOS App Architectures VIPER Rajat Datta CocoaCoder
  • 2. What is the Problem? • Massive View Controllers • Model objects (Core Data) are typically quite simple • Views are combinations of UIKit components • do not have access to models • Only interaction with Controllers is via IBActions • View Controllers get everything else!
  • 3. • What goes into View Controllers? • Data sources for Views (UITableView DataSource) • Business Logic • Application flow • transition between view controllers • VIPER is one proposal for a different app structure.
  • 4. References • WWDC 2014 video: Advanced User Interfaces with Collection Views • Viper (MutualMobile): http://www.objc.io/issue-13/viper.html • MVVM Pattern from Microsoft: http://msdn.microsoft.com/en-us/ library/hh848246.aspx • The Clean Architecture (Uncle Bob): http://blog.8thlight.com/ uncle-bob/2012/08/13/the-clean-architecture.html • For the academically oriented: Object-Oriented Software Construction by Bertrand Meyer
  • 5. • Lighter weight articles: • Clean Table View Code: http://www.objc.io/ issue-1/table-views.html • Lighter View Controllers: http://www.objc.io/ issue-1/lighter-view-controllers.html
  • 6. VIPER • V(iew) I(nteractor) P(resenter) E(ntity) R(outer) View Presenter Interactor Entity Entity Wireframe Data Store
  • 7. Views • UIKit components (UILabel, UITableView, …) • Presents a public interface that can be used to drive the UI • Views are completely passive; they don’t ask for the data to be shown. • implemented as public methods (ie. showName:(NSString *)name) • Defines an event interface triggered by IBActions, gestures • implemented as @protocol methods • ie. - (void)addEventAction:(id)sender; • The View Controller implements these two interfaces
  • 8. Presenter (PONSO) • Drives the UI using the View public and event interfaces • Sends requests to the Interactor • with data entered in the View • for data to be presented in the View • Data are simple models, not entities • mostly read/only; no business logic can be applied • absolutely no notion of persistence is applied to these data models • Sends requests to the Wireframe for UI transitions • ie. for Add action, request the Wireframe to transition to Add View.
  • 9. • Presenter can be a number of related objects • View:showName: method with NSString * • View:showTable: method with DataSource object • object is owned by Presenter
  • 10. Wireframe (PONSO) • Owns the UIWindow, UINavigationController and all UIViewControllers • Presents an action interface for the Presenter • Responsible for transition animations. • Can work with Storyboards • for more complex flows • use Storyboard IDs and instantiate in code
  • 11. Interactor (PONSO) • Each Interactor represents a single use-case in the app • All business logic is contained in the Interactor • Totally independent of UI, and can/should be covered by test cases. • This is where the core of all application dependencies will be found. • Fetches Entities from the Data Store • Passes and receives Models from the Presenter
  • 12. Entities (PONSO) • Created by the Data Store • Object contents are modified by the Interactor • Is not a managed object. Entities do not know how to persist themselves. • Just data structures. App dependent logic should be in an Interactor.
  • 13. Data Store • Responsible for presenting Entities to the Interactor • All persistence decisions are made here. • Can be replaced by a test double (mock). • Can be independently tested.
  • 14. Demo App • Journal App • Journal Entry • Date and Time • Text • Last edit Date and Time • Use Cases • Add Journal Entry • Show Journal Entries • Edit an existing Journal Entry • Persistence • Core Data • Cloudkit?
  • 15. Views • List View • Presenter starts the view with a datasource containing list of entries • from date, to date fields • when set, calls back via protocol method to the Presenter, which presents the view with a new datasource. • Edit Action (gesture on Table View?) • call back via protocol method to the Presenter, along with which journal entry selected. • Add Action (button?) • call back via protocol method to the Presenter.
  • 16. Presenter • Initially, call Interactor and fetch journal entries for last 30 days • Call View:showJournalList: with datasource containing list of journal entries; • callback from view with from and to dates; fetch data from Interactor and call View:showJournalList with that list • callback from view with edit action and journal entry; call to Wireframe to switch UI to Edit mode; • callback from view with add action; call to wireframe to switch UI to Add mode.
  • 17. Interactor • For View Action • method to fetch all journal articles for last 30 days; also returns from date, to date • method which, given from date, to date, returns the list of journal entries within that time (inclusive). • For Add action • method which, given a date and time, returns a new, empty, journal entry • contains only the id for the entry (unix timestamp) • method which, given id and journal entry, calls the data store to save a new journal entry.
  • 18. Entity • Data structure that Interactor passes along to the Data Store and back; • id (unix timestamp) for the journal entry. This is expected to be unique. • text: NSAttributedString • to be complete, should support images and formatting information. • last edit time. • In this case, this can also be the model • shared between the Interactor and the Presenter.
  • 19. Wireframe • Switch to List View • Switch to Edit View • Switch to Add View
  • 20. Data Store • in DataStore:init method, setup the Core Data sqlite store • DataStore:newJournalEntry • DataStore:fetchJournalEntriesFromDate:toDate: • DataStore:changedJournalEntry:
  • 21. Edge Cases • Out of band information • network access status; simple case • Push notification informs app of new information • overlay Presenter, on top of existing Presenter • overlay Presenter can ask Wireframe to change the UI. • Presenter can offer method that puts a Presenter to sleep • For games, stop the game clock.
  • 22. Flow Controllers • Reference: http://albertodebortoli.github.io/blog/ 2014/09/03/flow-controllers-on-ios-for-a-better-navigation- control/ • Flow Controllers manage navigation control • are passed along from view controller to view controller • are initialized with the navigation controller instance • Basically, these are Presenter and Wireframe in one. • What about Storyboards?