SlideShare a Scribd company logo
ReactiveCocoa
Werner Ramaekers
Jan Sabbe
Cocoaheads BE
12/03/2014
ReactiveCocoa (RAC) 
is an Objective-C framework for 
Functional Reactive
Programming.

It provides APIs for composing
and transforming streams of
values.
Whut ?
Programming
PIN OUT
Take inputs Produce outputs
Imperative programming
•int x; int y = 1; int z = 2;
•x = y + z; //x == 3; y == 1; z == 2;
!
PIN OUT
Imperative programming
•int x; int y = 1; int z = 2;
•x = y + z; //x == 3; y == 1; z == 2;
!
PIN OUT
•y = 2;
•NSLog(@“%i”, x); //-> ‘3’ 
!
# Input changed but output did NOT because it was
declared earlier….
Imperative programming
•int x; int y = 1; int z = 2;
•x = y + z; //x == 3; y == 1; z == 2;
!
PIN OUT
STATE•y = 2;
•NSLog(@“%i”, x); //-> ‘3’ 
!
# Input changed but output did NOT because it was
declared earlier….
Declaractive programming
•The developer describes the problem
domain in a declarative way, 
!
•The focus is NOT on state
!
•Focus is on :
•data flow
•propagation of change
Functional Programming
•is one way of declarative programming.
!
•Functional programming..
•deemphasizes state & mutable data
•emphasizes functions that produce
outputs based on inputs : z = f(x, y)
PIN OUT
Reactive Programming
•also is a way of declarative
programming
!
•Reactive Programming ..
•dynamically links the program’s behaviour
to its continuously updating data stream
PIN OUT
Reactive Programming
•also is a way of declarative
programming
!
•Reactive Programming ..
•dynamically links the program’s behaviour
to its continuously updating data stream
PIN OUT
•E.g. : a spreadsheet application where 
•cell A1 (= B1 + C1)
Functional Reactive Programming
•.. combines the FUNCTIONAL and
REACTIVE programming styles.
!
•.. links functions that observe
continuous and dynamic streams of
data (inputs) to the program’s
behaviour (outputs) in real time.
ReactiveCocoa (RAC) 
is an Objective-C framework for 
Functional Reactive
Programming.

It provides APIs for composing
and transforming streams of
values.
RAC : ReActiveCocoa
Stream Subscriber
RACStream produces a Stream existing of …
RAC : ReActiveCocoa
Stream
Next Event
Subscriber
RACStream produces a Stream existing of …
RAC : ReActiveCocoa
Stream
Next Event
Complete Event
Subscriber
RACStream produces a Stream existing of …
RAC : ReActiveCocoa
Stream
Next Event
Complete Event
Subscriber
Error Event
RACStream produces a Stream existing of …
RAC : ReActiveCocoa
Stream Subscriber
[ 1, 2, 3]
RACSequence
RAC : ReActiveCocoa
Stream Subscriber
[ 1, 2, 3]
123
RACSequence
RAC : ReActiveCocoa
Stream Subscriber
RACSignal
Client Server
RAC : ReActiveCocoa
Stream Subscriber…
JSON
RACSignal
Client Server
RAC : ReActiveCocoa
Stream Subscriber…
∞
RACSignal
Client
listen
RAC : ReActiveCocoa
RACStream
RACSignal RACSequence
ReactiveCocoa
•RACStream
•abstract class
•represents some sequential flow of data
•RACSignal (cold)
•push-driven data stream of future values
•cfr Network call
•must be subscribed to in order to access data
•RACSequence
•pull-driven data stream
•similar to Cocoa collection classes (NSArray, ..)
•but values are evaluated lazily - only when needed
Details please
RACSignal
!
[self.textField.rac_textSignal subscribeNext:^(id x) {
NSLog(@“New value : %@“, x);
} error:^(NSError *error){
NSLog(@“Error : %@“, error);
} completed:^{
NSLog(@“That’s all folks !”);
}];
RACSignal
!
[self.textField.rac_textSignal subscribeNext:^(id x) {
NSLog(@“New value : %@“, x);
!
!
!
!
}];
RACSignal : combineLatest
123
C.L.
( )=,
RACStream operators
•Simplifies transformations of streams into
new streams
•map, filter, fold/reduce
!
RACStream : map
MAP =
( ) =
RACSequence *stream = [@[@(1), @(2), @(3)] rac_sequence];
[stream map:^id(id value) {
return @(pow([value integerValue], 2));
}];
NSLog(@“%@“, [stream array]);
RACStream : flatten map
FMAP =
( ) =
Function result = stream
RACStream : filter
RACSequence *stream = [@[@(1), @(2), @(3)]; rac_sequence];
NSLog(@“%@“,
[[[array rac_sequence] filter:^BOOL(id value){
return [value integerValue] % 2 == 0;
}] array]
);
Filter =
( ) = True
?
Validating input the “old” way
#pragma mark - UITextFieldDelegate
!
- (BOOL) textField:(UITextField *)textField
shouldChangeCharactersInRange:(NSRange)range
replacementString:(NSString *)string
{
self.createButton.enabled = [self isFormValid];
!
return YES;
}
Validating input the “old” way
#pragma mark - UITextFieldDelegate
!
- (BOOL) textField:(UITextField *)textField
shouldChangeCharactersInRange:(NSRange)range
replacementString:(NSString *)string
{
self.createButton.enabled = [self isFormValid];
!
return YES;
}
- (BOOL)isFormValid {
return [self.usernameField.text length] > 0 &&
[self.emailField.text length] > 0 &&
[self.passwordField.text length] > 0 &&
[self.passwordField.text
isEqual:self.passwordVerificationField.text];
}
…
……
…
Validating input the “RAC” way
RAC(self.createButton, enabled) =
!
[RACSignal combineLatest:@[
self.usernameTF.rac_textSignal,
self.emailFieldTF.rac_textSignal,
self.passwordFieldTF.rac_textSignal,
self.passwordVerificationFieldTF.rac_textSignal
]
reduce:^(NSString *username,
NSString *email,
NSString *password,
NSString *passwordVerification) {
return @([username length] > 0 &&
[email length] > 0 &&
[password length] > 8 &&
[password isEqual:passwordVerification]);
}];
Validating input the “RAC” way
RAC(self.createButton, enabled) =
!
[RACSignal combineLatest:@[
self.usernameTF.rac_textSignal,
self.emailFieldTF.rac_textSignal,
self.passwordFieldTF.rac_textSignal,
self.passwordVerificationFieldTF.rac_textSignal
]
reduce:^(NSString *username,
NSString *email,
NSString *password,
NSString *passwordVerification) {
return @([username length] > 0 &&
[email length] > 0 &&
[password length] > 8 &&
[password isEqual:passwordVerification]);
}];
“not so fast cowboy .. “
•RAC(object, key path) is a macro
•creates a one-way binding
•ex. bind “enabled” property of a UIButton to a
signal
Now, show me a real app
Station locator app
Station locator app
Station locator app
Station locator app
Core Data
Stations
GPS coord
Services
Prices
Station locator app
Core Data
Stations
GPS coord
Services
Prices
Driving 
distance
Station locator app
Prices.xml
Core Data
Stations
GPS coord
Services
Prices
Driving 
distance
Station locator app
Stations.xml Prices.xml
Core Data
Stations
GPS coord
Services
Prices
Driving 
distance
Easier asynchronous code
Driving 
distance
1
2
3 Core Data lookup in Background
current location
RAC( ) = (51.2, 5.46)
station (id=4)
flattenMap 

searchClosest(51.2,5.46)
flattenMap 

getDrivingDistance(4)
JSON
map 

JSON -> km
"4.5 km"
Sort stations by driving distance
station (id=1)
station (id=3)
station (id=2)
getDrivingDistance
combineLatest 

sort [3,1,2]
fetching driving distances concurrently
when all available, sort
MVC
MVC
Scott, 
how do we test
UIViewControllers
ViewModel pattern
ViewController

sets up binding

animations
ViewModel

(BOOL) shop

(BOOL) bread

(RACCommand) search
SearchService

(RACSignal)
searchWithCriteria
validates + delegate to service
do actual search
ViewModel pattern
ViewController

sets up binding

animations
ViewModel

(BOOL) shop

(BOOL) bread

(RACCommand) search
SearchService

(RACSignal)
searchWithCriteria
mock out the real search service
do search against in memory DB
easily testable
harder to test
hard to test but trivial
ViewModel pattern
ViewController

sets up binding

animations
ViewModel

(BOOL) shop

(BOOL) bread

(RACCommand) search
SearchService

(RACSignal)
searchWithCriteria
validates + delegate to service
do actual search
what is this?
RACCommand
while getting current location, searching stations, sort by driving distance,... show activity indicator
[[RACCommand alloc] initWithSignalBlock:^RACSignal *(id sender) {
return [self createSearchSignal];
}];
ViewModel
RACCommand
while getting current location, searching stations, sort by driving distance,... show activity indicator
[[RACCommand alloc] initWithSignalBlock:^RACSignal *(id sender) {
return [self createSearchSignal];
}];
ViewModel
ViewController
self.searchButton.rac_command = self.viewModel.searchCommand;
RAC(self, spinner.hidden) = [self.viewModel.searchCommand.executing not];
ReactiveCocoa …
•keeps the app focused on representing data
& UX
•can reduce complexity bc you don’t need to
worry about ‘state’ so much
•keeps related code close together (via
blocks)
•helps to make your code more testable (via
MVVM)
but ReactiveCocoa …
•introduces another way of thinking.
•adds another learning curve on top of
Cocoa
!
•is a framework by GitHub and not Apple
!
•will Apple "sherlock" ReactiveCocoa ?
One last thing
Thank you

More Related Content

What's hot

Java 8 - functional features
Java 8 - functional featuresJava 8 - functional features
Java 8 - functional features
Rafal Rybacki
 
Function
Function Function
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
Shuvongkor Barman
 
Compiler Construction for DLX Processor
Compiler Construction for DLX Processor Compiler Construction for DLX Processor
Compiler Construction for DLX Processor
Soham Kulkarni
 
Compiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone FrameworksCompiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone Frameworks
Eelco Visser
 
C++ functions
C++ functionsC++ functions
C++ functions
Mayank Jain
 
C++ functions
C++ functionsC++ functions
C++ functions
Dawood Jutt
 
Mapfilterreducepresentation
MapfilterreducepresentationMapfilterreducepresentation
Mapfilterreducepresentation
ManjuKumara GH
 
C++ functions presentation by DHEERAJ KATARIA
C++ functions presentation by DHEERAJ KATARIAC++ functions presentation by DHEERAJ KATARIA
C++ functions presentation by DHEERAJ KATARIA
Dheeraj Kataria
 
Inroduction to r
Inroduction to rInroduction to r
Inroduction to r
manikanta361
 
Java8
Java8Java8
Cpp functions
Cpp functionsCpp functions
Cpp functions
NabeelaNousheen
 
User Defined Functions in MATLAB part 2
User Defined Functions in MATLAB part 2User Defined Functions in MATLAB part 2
User Defined Functions in MATLAB part 2
Shameer Ahmed Koya
 
INTRODUCTION TO C PROGRAMMING - PART 2
INTRODUCTION TO C PROGRAMMING - PART 2INTRODUCTION TO C PROGRAMMING - PART 2
INTRODUCTION TO C PROGRAMMING - PART 2
JEENA SARA VIJU
 
Introduction to functional programming
Introduction to functional programmingIntroduction to functional programming
Introduction to functional programming
Konrad Szydlo
 
Function and types
Function  and typesFunction  and types
Function and types
Sherin Fathima
 
Modular Programming in C
Modular Programming in CModular Programming in C
Modular Programming in C
bhawna kol
 
Functions in c
Functions in cFunctions in c
Functions in c
sunila tharagaturi
 
User defined Functions in MATLAB Part 1
User defined Functions in MATLAB Part 1User defined Functions in MATLAB Part 1
User defined Functions in MATLAB Part 1
Shameer Ahmed Koya
 
C functions
C functionsC functions

What's hot (20)

Java 8 - functional features
Java 8 - functional featuresJava 8 - functional features
Java 8 - functional features
 
Function
Function Function
Function
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
Compiler Construction for DLX Processor
Compiler Construction for DLX Processor Compiler Construction for DLX Processor
Compiler Construction for DLX Processor
 
Compiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone FrameworksCompiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone Frameworks
 
C++ functions
C++ functionsC++ functions
C++ functions
 
C++ functions
C++ functionsC++ functions
C++ functions
 
Mapfilterreducepresentation
MapfilterreducepresentationMapfilterreducepresentation
Mapfilterreducepresentation
 
C++ functions presentation by DHEERAJ KATARIA
C++ functions presentation by DHEERAJ KATARIAC++ functions presentation by DHEERAJ KATARIA
C++ functions presentation by DHEERAJ KATARIA
 
Inroduction to r
Inroduction to rInroduction to r
Inroduction to r
 
Java8
Java8Java8
Java8
 
Cpp functions
Cpp functionsCpp functions
Cpp functions
 
User Defined Functions in MATLAB part 2
User Defined Functions in MATLAB part 2User Defined Functions in MATLAB part 2
User Defined Functions in MATLAB part 2
 
INTRODUCTION TO C PROGRAMMING - PART 2
INTRODUCTION TO C PROGRAMMING - PART 2INTRODUCTION TO C PROGRAMMING - PART 2
INTRODUCTION TO C PROGRAMMING - PART 2
 
Introduction to functional programming
Introduction to functional programmingIntroduction to functional programming
Introduction to functional programming
 
Function and types
Function  and typesFunction  and types
Function and types
 
Modular Programming in C
Modular Programming in CModular Programming in C
Modular Programming in C
 
Functions in c
Functions in cFunctions in c
Functions in c
 
User defined Functions in MATLAB Part 1
User defined Functions in MATLAB Part 1User defined Functions in MATLAB Part 1
User defined Functions in MATLAB Part 1
 
C functions
C functionsC functions
C functions
 

Viewers also liked

Ruby on Rails for media
Ruby on Rails for mediaRuby on Rails for media
Ruby on Rails for media
Werner Ramaekers
 
Channl.tv
Channl.tvChannl.tv
Channl.tv
Werner Ramaekers
 
Technology 2.0
Technology 2.0Technology 2.0
Technology 2.0
Joaquín Salvachúa
 
Social networks upm
Social networks upmSocial networks upm
Social networks upm
Joaquín Salvachúa
 
Id fiware upm-dit
Id fiware  upm-ditId fiware  upm-dit
Id fiware upm-dit
Joaquín Salvachúa
 
FIWARE Identity Manager Exercises
FIWARE Identity Manager ExercisesFIWARE Identity Manager Exercises
FIWARE Identity Manager Exercises
Joaquín Salvachúa
 
Video platforms on internet
Video platforms on internetVideo platforms on internet
Video platforms on internet
Werner Ramaekers
 
Whats Web 2.0 Got To Do With Research?
Whats Web 2.0 Got To Do With Research?Whats Web 2.0 Got To Do With Research?
Whats Web 2.0 Got To Do With Research?
Timothy Collinson
 
Gtd
GtdGtd
Blogs micro
Blogs microBlogs micro
Blogs micro
Joaquín Salvachúa
 
Arq Mysql
Arq MysqlArq Mysql
Books For Web 2.0 A-Z
Books For Web 2.0 A-ZBooks For Web 2.0 A-Z
Books For Web 2.0 A-Z
Timothy Collinson
 
FIware Identity Manager
FIware Identity ManagerFIware Identity Manager
FIware Identity Manager
Joaquín Salvachúa
 
Development Logics - Introduction
Development Logics - IntroductionDevelopment Logics - Introduction
Development Logics - Introduction
Varun Rattan Singh
 
06 Busqueda
06 Busqueda06 Busqueda
06 Busqueda
Joaquín Salvachúa
 
Blogs Busqueda Iba
Blogs Busqueda IbaBlogs Busqueda Iba
Blogs Busqueda Iba
Joaquín Salvachúa
 
IP-TV : challenges for a broadcaster
IP-TV : challenges for a broadcasterIP-TV : challenges for a broadcaster
IP-TV : challenges for a broadcaster
Werner Ramaekers
 
Online news sites and their video usage
Online news sites and their video usageOnline news sites and their video usage
Online news sites and their video usageWerner Ramaekers
 

Viewers also liked (18)

Ruby on Rails for media
Ruby on Rails for mediaRuby on Rails for media
Ruby on Rails for media
 
Channl.tv
Channl.tvChannl.tv
Channl.tv
 
Technology 2.0
Technology 2.0Technology 2.0
Technology 2.0
 
Social networks upm
Social networks upmSocial networks upm
Social networks upm
 
Id fiware upm-dit
Id fiware  upm-ditId fiware  upm-dit
Id fiware upm-dit
 
FIWARE Identity Manager Exercises
FIWARE Identity Manager ExercisesFIWARE Identity Manager Exercises
FIWARE Identity Manager Exercises
 
Video platforms on internet
Video platforms on internetVideo platforms on internet
Video platforms on internet
 
Whats Web 2.0 Got To Do With Research?
Whats Web 2.0 Got To Do With Research?Whats Web 2.0 Got To Do With Research?
Whats Web 2.0 Got To Do With Research?
 
Gtd
GtdGtd
Gtd
 
Blogs micro
Blogs microBlogs micro
Blogs micro
 
Arq Mysql
Arq MysqlArq Mysql
Arq Mysql
 
Books For Web 2.0 A-Z
Books For Web 2.0 A-ZBooks For Web 2.0 A-Z
Books For Web 2.0 A-Z
 
FIware Identity Manager
FIware Identity ManagerFIware Identity Manager
FIware Identity Manager
 
Development Logics - Introduction
Development Logics - IntroductionDevelopment Logics - Introduction
Development Logics - Introduction
 
06 Busqueda
06 Busqueda06 Busqueda
06 Busqueda
 
Blogs Busqueda Iba
Blogs Busqueda IbaBlogs Busqueda Iba
Blogs Busqueda Iba
 
IP-TV : challenges for a broadcaster
IP-TV : challenges for a broadcasterIP-TV : challenges for a broadcaster
IP-TV : challenges for a broadcaster
 
Online news sites and their video usage
Online news sites and their video usageOnline news sites and their video usage
Online news sites and their video usage
 

Similar to Reactive cocoa cocoaheadsbe_2014

Luis Atencio on RxJS
Luis Atencio on RxJSLuis Atencio on RxJS
Luis Atencio on RxJS
Luis Atencio
 
Functional Reactive Programming (CocoaHeads Bratislava)
Functional Reactive Programming (CocoaHeads Bratislava)Functional Reactive Programming (CocoaHeads Bratislava)
Functional Reactive Programming (CocoaHeads Bratislava)
Michal Grman
 
Reactive Cocoa
Reactive CocoaReactive Cocoa
Reactive Cocoa
Robert Brown
 
Practical RxJava for Android
Practical RxJava for AndroidPractical RxJava for Android
Practical RxJava for Android
Tomáš Kypta
 
Reactive cocoa made Simple with Swift
Reactive cocoa made Simple with SwiftReactive cocoa made Simple with Swift
Reactive cocoa made Simple with Swift
Colin Eberhardt
 
Learn You a ReactiveCocoa for Great Good
Learn You a ReactiveCocoa for Great GoodLearn You a ReactiveCocoa for Great Good
Learn You a ReactiveCocoa for Great Good
Jason Larsen
 
RxJava applied [JavaDay Kyiv 2016]
RxJava applied [JavaDay Kyiv 2016]RxJava applied [JavaDay Kyiv 2016]
RxJava applied [JavaDay Kyiv 2016]
Igor Lozynskyi
 
Lviv MD Day 2015 Павло Захаров "Reactive cocoa: paradigm shift"
Lviv MD Day 2015 Павло Захаров "Reactive cocoa: paradigm shift"Lviv MD Day 2015 Павло Захаров "Reactive cocoa: paradigm shift"
Lviv MD Day 2015 Павло Захаров "Reactive cocoa: paradigm shift"
Lviv Startup Club
 
Structuring Spark: DataFrames, Datasets, and Streaming by Michael Armbrust
Structuring Spark: DataFrames, Datasets, and Streaming by Michael ArmbrustStructuring Spark: DataFrames, Datasets, and Streaming by Michael Armbrust
Structuring Spark: DataFrames, Datasets, and Streaming by Michael Armbrust
Spark Summit
 
Functional UIs with Java 8 and Vaadin JavaOne2014
Functional UIs with Java 8 and Vaadin JavaOne2014Functional UIs with Java 8 and Vaadin JavaOne2014
Functional UIs with Java 8 and Vaadin JavaOne2014
hezamu
 
Scalable Angular 2 Application Architecture
Scalable Angular 2 Application ArchitectureScalable Angular 2 Application Architecture
Scalable Angular 2 Application Architecture
FDConf
 
SparkSQL: A Compiler from Queries to RDDs
SparkSQL: A Compiler from Queries to RDDsSparkSQL: A Compiler from Queries to RDDs
SparkSQL: A Compiler from Queries to RDDs
Databricks
 
Kick your database_to_the_curb_reston_08_27_19
Kick your database_to_the_curb_reston_08_27_19Kick your database_to_the_curb_reston_08_27_19
Kick your database_to_the_curb_reston_08_27_19
confluent
 
JS Fest 2019. Anjana Vakil. Serverless Bebop
JS Fest 2019. Anjana Vakil. Serverless BebopJS Fest 2019. Anjana Vakil. Serverless Bebop
JS Fest 2019. Anjana Vakil. Serverless Bebop
JSFestUA
 
So you think you can stream.pptx
So you think you can stream.pptxSo you think you can stream.pptx
So you think you can stream.pptx
Prakash Chockalingam
 
Building a High-Performance Database with Scala, Akka, and Spark
Building a High-Performance Database with Scala, Akka, and SparkBuilding a High-Performance Database with Scala, Akka, and Spark
Building a High-Performance Database with Scala, Akka, and Spark
Evan Chan
 
Php my sql - functions - arrays - tutorial - programmerblog.net
Php my sql - functions - arrays - tutorial - programmerblog.netPhp my sql - functions - arrays - tutorial - programmerblog.net
Php my sql - functions - arrays - tutorial - programmerblog.net
Programmer Blog
 
GDG Jakarta Meetup - Streaming Analytics With Apache Beam
GDG Jakarta Meetup - Streaming Analytics With Apache BeamGDG Jakarta Meetup - Streaming Analytics With Apache Beam
GDG Jakarta Meetup - Streaming Analytics With Apache Beam
Imre Nagi
 
Introduction to reactive programming & ReactiveCocoa
Introduction to reactive programming & ReactiveCocoaIntroduction to reactive programming & ReactiveCocoa
Introduction to reactive programming & ReactiveCocoa
Florent Pillet
 
Leveraging R in Big Data of Mobile Ads (R在行動廣告大數據的應用)
Leveraging R in Big Data of Mobile Ads (R在行動廣告大數據的應用)Leveraging R in Big Data of Mobile Ads (R在行動廣告大數據的應用)
Leveraging R in Big Data of Mobile Ads (R在行動廣告大數據的應用)
Craig Chao
 

Similar to Reactive cocoa cocoaheadsbe_2014 (20)

Luis Atencio on RxJS
Luis Atencio on RxJSLuis Atencio on RxJS
Luis Atencio on RxJS
 
Functional Reactive Programming (CocoaHeads Bratislava)
Functional Reactive Programming (CocoaHeads Bratislava)Functional Reactive Programming (CocoaHeads Bratislava)
Functional Reactive Programming (CocoaHeads Bratislava)
 
Reactive Cocoa
Reactive CocoaReactive Cocoa
Reactive Cocoa
 
Practical RxJava for Android
Practical RxJava for AndroidPractical RxJava for Android
Practical RxJava for Android
 
Reactive cocoa made Simple with Swift
Reactive cocoa made Simple with SwiftReactive cocoa made Simple with Swift
Reactive cocoa made Simple with Swift
 
Learn You a ReactiveCocoa for Great Good
Learn You a ReactiveCocoa for Great GoodLearn You a ReactiveCocoa for Great Good
Learn You a ReactiveCocoa for Great Good
 
RxJava applied [JavaDay Kyiv 2016]
RxJava applied [JavaDay Kyiv 2016]RxJava applied [JavaDay Kyiv 2016]
RxJava applied [JavaDay Kyiv 2016]
 
Lviv MD Day 2015 Павло Захаров "Reactive cocoa: paradigm shift"
Lviv MD Day 2015 Павло Захаров "Reactive cocoa: paradigm shift"Lviv MD Day 2015 Павло Захаров "Reactive cocoa: paradigm shift"
Lviv MD Day 2015 Павло Захаров "Reactive cocoa: paradigm shift"
 
Structuring Spark: DataFrames, Datasets, and Streaming by Michael Armbrust
Structuring Spark: DataFrames, Datasets, and Streaming by Michael ArmbrustStructuring Spark: DataFrames, Datasets, and Streaming by Michael Armbrust
Structuring Spark: DataFrames, Datasets, and Streaming by Michael Armbrust
 
Functional UIs with Java 8 and Vaadin JavaOne2014
Functional UIs with Java 8 and Vaadin JavaOne2014Functional UIs with Java 8 and Vaadin JavaOne2014
Functional UIs with Java 8 and Vaadin JavaOne2014
 
Scalable Angular 2 Application Architecture
Scalable Angular 2 Application ArchitectureScalable Angular 2 Application Architecture
Scalable Angular 2 Application Architecture
 
SparkSQL: A Compiler from Queries to RDDs
SparkSQL: A Compiler from Queries to RDDsSparkSQL: A Compiler from Queries to RDDs
SparkSQL: A Compiler from Queries to RDDs
 
Kick your database_to_the_curb_reston_08_27_19
Kick your database_to_the_curb_reston_08_27_19Kick your database_to_the_curb_reston_08_27_19
Kick your database_to_the_curb_reston_08_27_19
 
JS Fest 2019. Anjana Vakil. Serverless Bebop
JS Fest 2019. Anjana Vakil. Serverless BebopJS Fest 2019. Anjana Vakil. Serverless Bebop
JS Fest 2019. Anjana Vakil. Serverless Bebop
 
So you think you can stream.pptx
So you think you can stream.pptxSo you think you can stream.pptx
So you think you can stream.pptx
 
Building a High-Performance Database with Scala, Akka, and Spark
Building a High-Performance Database with Scala, Akka, and SparkBuilding a High-Performance Database with Scala, Akka, and Spark
Building a High-Performance Database with Scala, Akka, and Spark
 
Php my sql - functions - arrays - tutorial - programmerblog.net
Php my sql - functions - arrays - tutorial - programmerblog.netPhp my sql - functions - arrays - tutorial - programmerblog.net
Php my sql - functions - arrays - tutorial - programmerblog.net
 
GDG Jakarta Meetup - Streaming Analytics With Apache Beam
GDG Jakarta Meetup - Streaming Analytics With Apache BeamGDG Jakarta Meetup - Streaming Analytics With Apache Beam
GDG Jakarta Meetup - Streaming Analytics With Apache Beam
 
Introduction to reactive programming & ReactiveCocoa
Introduction to reactive programming & ReactiveCocoaIntroduction to reactive programming & ReactiveCocoa
Introduction to reactive programming & ReactiveCocoa
 
Leveraging R in Big Data of Mobile Ads (R在行動廣告大數據的應用)
Leveraging R in Big Data of Mobile Ads (R在行動廣告大數據的應用)Leveraging R in Big Data of Mobile Ads (R在行動廣告大數據的應用)
Leveraging R in Big Data of Mobile Ads (R在行動廣告大數據的應用)
 

Recently uploaded

How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Data structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdfData structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdf
TIPNGVN2
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 

Recently uploaded (20)

How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Data structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdfData structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdf
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 

Reactive cocoa cocoaheadsbe_2014

  • 2.
  • 3.
  • 4. ReactiveCocoa (RAC) is an Objective-C framework for Functional Reactive Programming. It provides APIs for composing and transforming streams of values.
  • 7. Imperative programming •int x; int y = 1; int z = 2; •x = y + z; //x == 3; y == 1; z == 2; ! PIN OUT
  • 8. Imperative programming •int x; int y = 1; int z = 2; •x = y + z; //x == 3; y == 1; z == 2; ! PIN OUT •y = 2; •NSLog(@“%i”, x); //-> ‘3’ ! # Input changed but output did NOT because it was declared earlier….
  • 9. Imperative programming •int x; int y = 1; int z = 2; •x = y + z; //x == 3; y == 1; z == 2; ! PIN OUT STATE•y = 2; •NSLog(@“%i”, x); //-> ‘3’ ! # Input changed but output did NOT because it was declared earlier….
  • 10. Declaractive programming •The developer describes the problem domain in a declarative way, ! •The focus is NOT on state ! •Focus is on : •data flow •propagation of change
  • 11. Functional Programming •is one way of declarative programming. ! •Functional programming.. •deemphasizes state & mutable data •emphasizes functions that produce outputs based on inputs : z = f(x, y) PIN OUT
  • 12. Reactive Programming •also is a way of declarative programming ! •Reactive Programming .. •dynamically links the program’s behaviour to its continuously updating data stream PIN OUT
  • 13. Reactive Programming •also is a way of declarative programming ! •Reactive Programming .. •dynamically links the program’s behaviour to its continuously updating data stream PIN OUT •E.g. : a spreadsheet application where •cell A1 (= B1 + C1)
  • 14. Functional Reactive Programming •.. combines the FUNCTIONAL and REACTIVE programming styles. ! •.. links functions that observe continuous and dynamic streams of data (inputs) to the program’s behaviour (outputs) in real time.
  • 15. ReactiveCocoa (RAC) is an Objective-C framework for Functional Reactive Programming. It provides APIs for composing and transforming streams of values.
  • 16. RAC : ReActiveCocoa Stream Subscriber RACStream produces a Stream existing of …
  • 17. RAC : ReActiveCocoa Stream Next Event Subscriber RACStream produces a Stream existing of …
  • 18. RAC : ReActiveCocoa Stream Next Event Complete Event Subscriber RACStream produces a Stream existing of …
  • 19. RAC : ReActiveCocoa Stream Next Event Complete Event Subscriber Error Event RACStream produces a Stream existing of …
  • 20. RAC : ReActiveCocoa Stream Subscriber [ 1, 2, 3] RACSequence
  • 21. RAC : ReActiveCocoa Stream Subscriber [ 1, 2, 3] 123 RACSequence
  • 22. RAC : ReActiveCocoa Stream Subscriber RACSignal Client Server
  • 23. RAC : ReActiveCocoa Stream Subscriber… JSON RACSignal Client Server
  • 24. RAC : ReActiveCocoa Stream Subscriber… ∞ RACSignal Client listen
  • 26. ReactiveCocoa •RACStream •abstract class •represents some sequential flow of data •RACSignal (cold) •push-driven data stream of future values •cfr Network call •must be subscribed to in order to access data •RACSequence •pull-driven data stream •similar to Cocoa collection classes (NSArray, ..) •but values are evaluated lazily - only when needed
  • 28. RACSignal ! [self.textField.rac_textSignal subscribeNext:^(id x) { NSLog(@“New value : %@“, x); } error:^(NSError *error){ NSLog(@“Error : %@“, error); } completed:^{ NSLog(@“That’s all folks !”); }];
  • 29. RACSignal ! [self.textField.rac_textSignal subscribeNext:^(id x) { NSLog(@“New value : %@“, x); ! ! ! ! }];
  • 31. RACStream operators •Simplifies transformations of streams into new streams •map, filter, fold/reduce !
  • 32. RACStream : map MAP = ( ) = RACSequence *stream = [@[@(1), @(2), @(3)] rac_sequence]; [stream map:^id(id value) { return @(pow([value integerValue], 2)); }]; NSLog(@“%@“, [stream array]);
  • 33. RACStream : flatten map FMAP = ( ) = Function result = stream
  • 34. RACStream : filter RACSequence *stream = [@[@(1), @(2), @(3)]; rac_sequence]; NSLog(@“%@“, [[[array rac_sequence] filter:^BOOL(id value){ return [value integerValue] % 2 == 0; }] array] ); Filter = ( ) = True ?
  • 35.
  • 36. Validating input the “old” way #pragma mark - UITextFieldDelegate ! - (BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { self.createButton.enabled = [self isFormValid]; ! return YES; }
  • 37. Validating input the “old” way #pragma mark - UITextFieldDelegate ! - (BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { self.createButton.enabled = [self isFormValid]; ! return YES; } - (BOOL)isFormValid { return [self.usernameField.text length] > 0 && [self.emailField.text length] > 0 && [self.passwordField.text length] > 0 && [self.passwordField.text isEqual:self.passwordVerificationField.text]; } … …… …
  • 38.
  • 39. Validating input the “RAC” way RAC(self.createButton, enabled) = ! [RACSignal combineLatest:@[ self.usernameTF.rac_textSignal, self.emailFieldTF.rac_textSignal, self.passwordFieldTF.rac_textSignal, self.passwordVerificationFieldTF.rac_textSignal ] reduce:^(NSString *username, NSString *email, NSString *password, NSString *passwordVerification) { return @([username length] > 0 && [email length] > 0 && [password length] > 8 && [password isEqual:passwordVerification]); }];
  • 40. Validating input the “RAC” way RAC(self.createButton, enabled) = ! [RACSignal combineLatest:@[ self.usernameTF.rac_textSignal, self.emailFieldTF.rac_textSignal, self.passwordFieldTF.rac_textSignal, self.passwordVerificationFieldTF.rac_textSignal ] reduce:^(NSString *username, NSString *email, NSString *password, NSString *passwordVerification) { return @([username length] > 0 && [email length] > 0 && [password length] > 8 && [password isEqual:passwordVerification]); }];
  • 41. “not so fast cowboy .. “ •RAC(object, key path) is a macro •creates a one-way binding •ex. bind “enabled” property of a UIButton to a signal
  • 42. Now, show me a real app
  • 46. Station locator app Core Data Stations GPS coord Services Prices
  • 47. Station locator app Core Data Stations GPS coord Services Prices Driving distance
  • 48. Station locator app Prices.xml Core Data Stations GPS coord Services Prices Driving distance
  • 49. Station locator app Stations.xml Prices.xml Core Data Stations GPS coord Services Prices Driving distance
  • 50. Easier asynchronous code Driving distance 1 2 3 Core Data lookup in Background current location
  • 51. RAC( ) = (51.2, 5.46) station (id=4) flattenMap 
 searchClosest(51.2,5.46) flattenMap 
 getDrivingDistance(4) JSON map 
 JSON -> km "4.5 km"
  • 52. Sort stations by driving distance station (id=1) station (id=3) station (id=2) getDrivingDistance combineLatest 
 sort [3,1,2] fetching driving distances concurrently when all available, sort
  • 53. MVC
  • 54. MVC
  • 55. Scott, how do we test UIViewControllers
  • 56. ViewModel pattern ViewController
 sets up binding
 animations ViewModel
 (BOOL) shop
 (BOOL) bread
 (RACCommand) search SearchService
 (RACSignal) searchWithCriteria validates + delegate to service do actual search
  • 57. ViewModel pattern ViewController
 sets up binding
 animations ViewModel
 (BOOL) shop
 (BOOL) bread
 (RACCommand) search SearchService
 (RACSignal) searchWithCriteria mock out the real search service do search against in memory DB easily testable harder to test hard to test but trivial
  • 58. ViewModel pattern ViewController
 sets up binding
 animations ViewModel
 (BOOL) shop
 (BOOL) bread
 (RACCommand) search SearchService
 (RACSignal) searchWithCriteria validates + delegate to service do actual search what is this?
  • 59. RACCommand while getting current location, searching stations, sort by driving distance,... show activity indicator [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id sender) { return [self createSearchSignal]; }]; ViewModel
  • 60. RACCommand while getting current location, searching stations, sort by driving distance,... show activity indicator [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id sender) { return [self createSearchSignal]; }]; ViewModel ViewController self.searchButton.rac_command = self.viewModel.searchCommand; RAC(self, spinner.hidden) = [self.viewModel.searchCommand.executing not];
  • 61. ReactiveCocoa … •keeps the app focused on representing data & UX •can reduce complexity bc you don’t need to worry about ‘state’ so much •keeps related code close together (via blocks) •helps to make your code more testable (via MVVM)
  • 62. but ReactiveCocoa … •introduces another way of thinking. •adds another learning curve on top of Cocoa ! •is a framework by GitHub and not Apple ! •will Apple "sherlock" ReactiveCocoa ?