SlideShare a Scribd company logo
Reactive VIPER
IVAN ĐIKIĆ
WHY?
UIVIEWCONTROLLER
(UIVIEW)
• workhorse
• hard to test
• hard to maintain
• not reusable
BUILDING BLOCK FOR COCOA TOUCH
VIPER
• in 4 parts
• good for medium to big size applications
• good separation of responsibility
• loosely coupled components
SPLIT UP VIEW CONTROLLER
• connection between components is achieved using protocols
• composition instead inheritance in most cases
• most of UI is done in Storyboards but without Segues
GENERAL
• View / View Controller
• Presenter (view model :))
• Interactor
• Wireframe
MAIN COMPONENTS
MAIN COMPONENTS
MAIN COMPONENTS
• business logic agnostic
• knows how to layout itself
• reusable
VIEW / VIEW CONTROLLER
• business logic
• least reusable part
• has reference to
• view
• interactor
• wireframe
• models data received from interactor
• views delegate (responds to view events)
PRESENTER
• has the data
• knows how to get the data
INTERACTOR
• knows how to navigate
• knows how to create other VIPER modules
WIREFRAME
RX(SWIFT)
• FRP
• functional programming
• functions don’t have side effects, no mutable state
• difficult to program since real world is all about side effects
• reactive programming
• changes propagate throughout a system automatically
• functional reactive programming
• we model user input as a function that changes over time,
abstracting away the idea of mutable state
CREATED BY MICROSOFT (RX.NET)
• sweet spot between functional and imperative programming world
• unifies various design patterns (GoF)
• Delegate
• Callback (Closures, Blocks)
• KVO
• Notifications
• Observer
• enables building apps in declarative style
WHY RX?
DECLARATIVE STYLE
Observable
.combineLatest
(
firstName.rx_text,
lastName.rx_text
)
{
$0 + " " + $1
}
.map {
"Greetings, ($0)"
}
.bindTo(greetingLabel.rx_text)
ITERATOR, OBSERVER
Observer and Iterator patterns are mathematical duals
CORE KNOWLEDGE
ITERATOR PATTERN
• pull based interface
• good for traversing collections
• standard interface
• generator
• next (pull)
• no more data
• throw (error)
• arrays, dictionaries, sets
ITERATOR
• a collection of protocols
• CollectionType
• SequenceType
• GeneratorType
ITERATOR IN SWIFT
GeneratorType
- serve elements
protocol GeneratorType {
associatedtype Element
mutating func next() -> Element?
}
SequenceType
- knows how to create generator
struct PrefixSequence: SequenceType {
let string: String
func generate() -> PrefixGenerator {
return PrefixGenerator(string: string)
}
}
CollectionType
- repeatable iteration
- access to the elements via index
struct BeersCollection<T> {
let beers: [T]
}
CollectionType
extension BeersCollection: SequenceType {
typealias Generator = AnyGenerator<T>
func generate() -> AnyGenerator<T> {
var i = 0
return AnyGenerator {
i += 1
return i >= self.beers.count
?
nil
:
self.beers[i]
}
}
}
OBSERVER PATTERN
• push based interface
• good for UI events
• missing
• error handling
• no more data
OBSERVER
Observer
protocol PropertyObserver : class {
func willChangePropertyName(propertyName: String, newPropertyValue: AnyObject?)
func didChangePropertyName(propertyName: String, oldPropertyValue: AnyObject?)
}
Observer
class TestChambers {
weak var observer: PropertyObserver?
var testChamberNumber: Int = 0 {
willSet(newValue) {
observer?.willChangePropertyName("testChamberNumber", newPropertyValue:newValue)
}
didSet {
observer?.didChangePropertyName("testChamberNumber", oldPropertyValue:oldValue)
}
}
}
OBSERVABLES
AKA
SEQUENCES
• unifying Iterator and Observer pattern
• can be composed
• we already know how to do operations on collections
• map
• filter
• reduce
• the equivalence of observer pattern (Observable<Element>
sequence) and normal sequences (SequenceType) is the most
important thing to understand about Rx
GENERAL
• every observable sequence is just a sequence
• push interface (aka callback)
• regex
• next* (error | completed)?
• can have 0 or more elements
• once error or completed
• sequence cannot produce any other element
• all internal resources will be disposed
• no work will be performed until you call subscribe
OBSERVABLES AKA SEQUENCES
TIPS’N’TRICKS
RTFM
AVOID NESTING CALLS
ALWAYS USE `DISPOSE BAG`
`SOURCEKIT` HAS CRASHED
USE [WEAK SELF]
PERIODICALLY PRINT RESOURCES
COUNT
STRIVE TO MODEL YOUR SYSTEMS AS
PURE FUNCTIONS
RESOURCES
RESOURCES
• RxSwift
• Reactive Programming Overview
• Design Patterns In Swift
• Inside .Net Reactive Framework
• Duality
• Visual Operators (RxMarbles)
Q&A

More Related Content

PDF
Infinum iOS Talks #2 - VIPER for everybody by Damjan Vujaklija
PDF
Introduction to VIPER Architecture
PDF
Break the monolith with (B)VIPER Modules
PDF
iOS viper presentation
PPTX
Sexy Architecting. VIPER: MVP on steroids
PDF
From mvc to viper
PDF
PPTX
VIPER Architecture
Infinum iOS Talks #2 - VIPER for everybody by Damjan Vujaklija
Introduction to VIPER Architecture
Break the monolith with (B)VIPER Modules
iOS viper presentation
Sexy Architecting. VIPER: MVP on steroids
From mvc to viper
VIPER Architecture

What's hot (20)

PDF
Rambler.iOS #5: Разбираем Massive View Controller
PDF
Web sockets in Angular
PPTX
Async patterns in javascript
PDF
Angular2 Development for Java developers
PDF
Angular 4 for Java Developers
PPTX
Introduction to Angular JS
PPTX
AngularJS intro
PPTX
AngularJS Beginners Workshop
PPTX
Angular js for beginners
PPTX
Angular 4
PPTX
The AngularJS way
PPTX
5 angularjs features
PPTX
Introduction to Angularjs
PPTX
Angular js 1.0-fundamentals
PPTX
AngularJs presentation
PPTX
Introduction to angular with a simple but complete project
PDF
Overview of the AngularJS framework
ODP
Angularjs
PPTX
Front end development with Angular JS
PDF
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
Rambler.iOS #5: Разбираем Massive View Controller
Web sockets in Angular
Async patterns in javascript
Angular2 Development for Java developers
Angular 4 for Java Developers
Introduction to Angular JS
AngularJS intro
AngularJS Beginners Workshop
Angular js for beginners
Angular 4
The AngularJS way
5 angularjs features
Introduction to Angularjs
Angular js 1.0-fundamentals
AngularJs presentation
Introduction to angular with a simple but complete project
Overview of the AngularJS framework
Angularjs
Front end development with Angular JS
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
Ad

Viewers also liked (17)

PDF
Infinum Android Talks #20 - DiffUtil
PDF
"Clean" Architecture
PDF
iOS Zagreb Meetup #02 - Clean architecture in iOS apps (Leonard Beus @ Five)
PDF
Infinum iOS Talks #4 - Making your Swift networking code more awesome with Re...
PDF
Dependence day insurgence
PDF
Infinum Android Talks #20 - Making your Android apps fast like Blue Runner an...
PDF
Why the Dark Side should use Swift and a SOLID Architecture
PDF
Jorge D. Ortiz Fuentes "Hands on Implementation of Clean Architecture for And...
PDF
Choosing the architecture
PDF
Clean architecture workshop
PDF
Protobuf & Code Generation + Go-Kit
PPTX
Lightning Talk - Clean Architecture and Design
PPTX
VIPER - Design Pattern
PDF
Introducing Clean Architecture
PDF
Rambler.iOS #5: VIPER и Swift
PPTX
Clean architecture
PPTX
iOS Coding Best Practices
Infinum Android Talks #20 - DiffUtil
"Clean" Architecture
iOS Zagreb Meetup #02 - Clean architecture in iOS apps (Leonard Beus @ Five)
Infinum iOS Talks #4 - Making your Swift networking code more awesome with Re...
Dependence day insurgence
Infinum Android Talks #20 - Making your Android apps fast like Blue Runner an...
Why the Dark Side should use Swift and a SOLID Architecture
Jorge D. Ortiz Fuentes "Hands on Implementation of Clean Architecture for And...
Choosing the architecture
Clean architecture workshop
Protobuf & Code Generation + Go-Kit
Lightning Talk - Clean Architecture and Design
VIPER - Design Pattern
Introducing Clean Architecture
Rambler.iOS #5: VIPER и Swift
Clean architecture
iOS Coding Best Practices
Ad

Similar to Infinum iOS Talks #4 - Making our VIPER more reactive (20)

PDF
Swift & ReactiveX – Asynchronous Event-Based Funsies with RxSwift
PDF
RxSwift
PDF
Reactive Programming with RxSwift
PDF
Introduction to reactive programming
PDF
[Rx] rx cocoa
PDF
"Universal programming recipes", Kateryna Trofimenko
PDF
Universal programming recipes​ - Ekaterina Trofimenko - Women In Technology
PDF
Reactive Programming Patterns with RxSwift
PDF
Reactive programming with cycle.js
PDF
Infinum iOS Talks #1 - Swift done right by Ivan Dikic
PDF
An introduction to functional programming with Swift
PDF
Reactive computing
PPTX
Rx for Android & iOS by Harin Trivedi
PDF
RxSwift Training
PDF
10 things you didn't know about RxSwift
PDF
Andrii Orlov "Generators Flexibility in Modern Code"
PDF
Reactive Thinking in iOS Development - Pedro Piñera Buendía - Codemotion Amst...
PDF
Reactive programming with RxSwift
PDF
PDF
响应式编程及框架
Swift & ReactiveX – Asynchronous Event-Based Funsies with RxSwift
RxSwift
Reactive Programming with RxSwift
Introduction to reactive programming
[Rx] rx cocoa
"Universal programming recipes", Kateryna Trofimenko
Universal programming recipes​ - Ekaterina Trofimenko - Women In Technology
Reactive Programming Patterns with RxSwift
Reactive programming with cycle.js
Infinum iOS Talks #1 - Swift done right by Ivan Dikic
An introduction to functional programming with Swift
Reactive computing
Rx for Android & iOS by Harin Trivedi
RxSwift Training
10 things you didn't know about RxSwift
Andrii Orlov "Generators Flexibility in Modern Code"
Reactive Thinking in iOS Development - Pedro Piñera Buendía - Codemotion Amst...
Reactive programming with RxSwift
响应式编程及框架

More from Infinum (20)

PDF
Infinum Android Talks #20 - Benefits of using Kotlin
PDF
Infinum Android Talks #13 - Using ViewDragHelper
PDF
Infinum Android Talks #14 - Log4j
PDF
Infinum Android Talks #9 - Making your app location-aware
PDF
Infinum Android Talks #14 - Gradle plugins
PDF
Infinum Android Talks #14 - Facebook for Android API
PDF
Infinum Android Talks #19 - Stop wasting time fixing bugs with TDD by Domagoj...
PDF
Infinum Android Talks #18 - Create fun lists by Ivan Marić
PDF
Infinum Android Talks #18 - In-app billing by Ivan Marić
PDF
Infinum Android Talks #18 - How to cache like a boss by Željko Plesac
PDF
Infinum iOS Talks #2 - Xamarin by Ivan Đikić
PDF
Infinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho Poluta
PDF
Infinum iOS Talks #1 - Becoming an iOS developer swiftly by Vedran Burojevic
PDF
Infinum Android Talks #17 - Testing your Android applications by Ivan Kust
PDF
Infinum Android Talks #17 - A quest for WebSockets by Zeljko Plesac
PDF
Infinum Android Talks #17 - Developing an Android library by Dino Kovac
PDF
Infinum Android Talks #17 - Intro by Ivan Kocijan
PDF
Android Meetup Slovenia #5 - Don't go crashing my heart by Zeljko Plesac, Inf...
PDF
Infinum Android Talks #16 - Enterprise app development with Samsung by Blaz S...
PDF
Infinum Android Talks #16 - Retrofit 2 by Kristijan Jurkovic
Infinum Android Talks #20 - Benefits of using Kotlin
Infinum Android Talks #13 - Using ViewDragHelper
Infinum Android Talks #14 - Log4j
Infinum Android Talks #9 - Making your app location-aware
Infinum Android Talks #14 - Gradle plugins
Infinum Android Talks #14 - Facebook for Android API
Infinum Android Talks #19 - Stop wasting time fixing bugs with TDD by Domagoj...
Infinum Android Talks #18 - Create fun lists by Ivan Marić
Infinum Android Talks #18 - In-app billing by Ivan Marić
Infinum Android Talks #18 - How to cache like a boss by Željko Plesac
Infinum iOS Talks #2 - Xamarin by Ivan Đikić
Infinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho Poluta
Infinum iOS Talks #1 - Becoming an iOS developer swiftly by Vedran Burojevic
Infinum Android Talks #17 - Testing your Android applications by Ivan Kust
Infinum Android Talks #17 - A quest for WebSockets by Zeljko Plesac
Infinum Android Talks #17 - Developing an Android library by Dino Kovac
Infinum Android Talks #17 - Intro by Ivan Kocijan
Android Meetup Slovenia #5 - Don't go crashing my heart by Zeljko Plesac, Inf...
Infinum Android Talks #16 - Enterprise app development with Samsung by Blaz S...
Infinum Android Talks #16 - Retrofit 2 by Kristijan Jurkovic

Recently uploaded (20)

PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Machine learning based COVID-19 study performance prediction
PDF
KodekX | Application Modernization Development
PDF
Empathic Computing: Creating Shared Understanding
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Approach and Philosophy of On baking technology
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
NewMind AI Weekly Chronicles - August'25 Week I
Review of recent advances in non-invasive hemoglobin estimation
Understanding_Digital_Forensics_Presentation.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Advanced methodologies resolving dimensionality complications for autism neur...
Network Security Unit 5.pdf for BCA BBA.
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Machine learning based COVID-19 study performance prediction
KodekX | Application Modernization Development
Empathic Computing: Creating Shared Understanding
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Encapsulation_ Review paper, used for researhc scholars
Approach and Philosophy of On baking technology
Chapter 3 Spatial Domain Image Processing.pdf
MYSQL Presentation for SQL database connectivity
CIFDAQ's Market Insight: SEC Turns Pro Crypto
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy

Infinum iOS Talks #4 - Making our VIPER more reactive