SlideShare a Scribd company logo
ReactiveCocoa
Bob Spryn
LoHi Labs
@sprynmr (github, twitter)
!
!
!

https://github.com/ReactiveCocoa/ReactiveCocoa
ReactiveCocoa
•

An implementation of functional reactive programming

•

It provides APIs for composing and transforming
streams of values

•

“Signals” send you these values over time for you to
react to

http://en.wikipedia.org/wiki/Functional_reactive_programming
?
Not just another API.

It enables you to

Program Smarter
Focus on WHAT not HOW
Reactive!!! Declarative!!!

What does that even mean?
• Setup

your reactions

• Compose,

Reactive!!! Declarative!!!

split, filter, etc.

What does that even mean?
Imperative
The way we normally program.
Imperative
The way we normally program.

•

Observe, wait, then command & control

•

Dealing with the HOW, not just the WHAT

•

Code for controlling flow is spread all over
Auto-layout : Managing Frames
ReactiveCocoa : Imperative programming
Complexity
Is
STATE
BOOL loadingNextPageOfComments;

2 states


BOOL commentsAreShowing;

4 states


BOOL commentsLoadingShowing;

8 states


BOOL flippingAnswers;

16 states


BOOL isOwnerOfQuestion;

32 states
- (void) updateChangeAnswerButtonText {
if (self.didAnswerQuestion && self.inResultsView) {
[self.commentHeaderCell configureWithStyle:TCQuestionDetailCommentHeaderCellChangeAnswer];
} else if (self.isOwnerOfQuestion && !self.didAnswerQuestion && self.inResultsView) {
[self.commentHeaderCell configureWithStyle:TCQuestionDetailCommentHeaderCellViewAnswers];
} else {
[self.commentHeaderCell configureWithStyle:TCQuestionDetailCommentHeaderCellViewStats];
}
}
- (void) updateViewCommentStatus {
if ((self.didAnswerQuestion || self.isOwnerOfQuestion) && !self.commentsAreShowing) {
self.commentsAreShowing = YES;
- (void) prepareForReuse {
self.commentsLoadingShowing = YES;
self.state = TCQuestionDetailViewContro
…
self.questionFullyLoaded = NO;
}
self.isOwnerOfQuestion = NO;
self.didAnswerQuestion = NO;
[self showCommentBox:self.inResultsView || self.isOwnerOfQuestion];
[self showCommentBox:NO];
}
self.loadingNextPageOfComments = NO;
self.commentsAreShowing = NO;
self.commentsLoadingShowing = NO;

!

^aBlock {
sself.didAnswerQuestion = sself.question.userResponse ? YES : NO;
sself.inResultsView = sself.didAnswerQuestion || self.isOwnerOfQuestion;
if (sself.questionFullyLoaded) {
return;
} …

}

}

l co
Rea

rom
ef
d

file
one
ReactiveCocoa to the Rescue!

•

Signals instead of mutable variables


•

RACSignal – Think of it as a beacon sending out new values to it’s
subscribers
RACSignal
•

A unified interface for observing and reacting to all kinds of events
and their values

•

UI Action


•

Async Network Call


•

KVO


•

Async Processing

t’s
I

in
ll
a

t!
pu
RACSignal
•

Shared vocabulary for transforming the received values

•

•

Combine, filter, reduce, map, and many more operations


Eventually generate output (side effects)

•

Updating a label


•

Update an array with objects from the network


•

etc.
- (void)viewDidLoad {

[super viewDidLoad];

[self.username

addTarget:self

action:@selector(textFieldTextDidChange:)

forControlEvents:UIControlEventAllEditingEvents];

[self.email

addTarget:self

action:@selector(textFieldTextDidChange:)

forControlEvents:UIControlEventAllEditingEvents];


Your name
Your email address
Sign Up

abled
ton.en
ut

gnUpB
si

}
!

- (void)textFieldTextDidChange:(UITextField *)field {

BOOL validUsername = self.username.text.length > 0;




NSRange at = [self.email.text rangeOfString:@"@"];




BOOL validEmail = at.location != NSNotFound;

self.signupButton.enabled = validUsername &&

validEmail;

}

Old

Solved the imperative way.
Your name
Your email address
RAC(self.signUpButton, enabled) = [RACSignal
combineLatest:@[

self.name.rac_textSignal,

self.email.rac_textSignal

]

reduce:^(NSString *name, NSString *email) {

NSRange at = [email rangeOfString:@"@"];
return @(at.location != NSNotFound && name.length > 0);

}];

Sign Up
ould I
Sh

SOME
AWE

bled?
e ena
b

Solved the reactive way.
Your name
Your email address
RAC(self.signUpButton, enabled) = [RACSignal
combineLatest:@[

self.name.rac_textSignal,

self.email.rac_textSignal

]

reduce:^(NSString *name, NSString *email) {

NSRange at = [email rangeOfString:@"@"];
return @(at.location != NSNotFound && name.length > 0);

}];

Sign Up
ould I
Sh

SOME
AWE

bled?
e ena
b

Solved the reactive way.
Network Validation?
Easy.

Your name
Your email address
Sign Up

RACSignal *validateEmailSignal = [self.email.rac_textSignal
map:^id(NSString *emailString) {
return [MyAPI validatedEmail:emailString];
}];

uld I
Sho

bled?
be ena

!

RAC(self.signUpButton, enabled) = [RACSignal
combineLatest:@[

self.name.rac_textSignal,

validateEmailSignal

]

reduce:^(NSString *name, APIResponse *response) {

return @(response.json.isValid == YES && name.length > 0);

}];

SOME
AWE

Solved the reactive way.
Network Validation?
Easy.

Your name
Your email address
Sign Up

RACSignal *validateEmailSignal =
map
}];
!

uld I
Sho

The point is to Minimize State

RAC
combineLatest

]
reduce
}];

Solved the

SOME
AWE

bled?
be ena
Network Validation?
Easy.

Your name
Your email address
Sign Up

RACSignal *validateEmailSignal =
map
}];
!

uld I
Sho

The point is to Minimize State

RAC
combineLatest

]
reduce
}];

Solved the

SOME
AWE

bled?
be ena
Check out ReactiveCocoa
Your Brain Will Thank You
https://github.com/ReactiveCocoa/ReactiveCocoa

Bob Spryn
LoHi Labs
@sprynmr (github, twitter)
!

Thanks to @jspahrsummers, @joshaber, @AshFurrow, @robb, @andrewsardone and @erikprice (github usernames)
for sharing their presentation slides and helping me learn ReactiveCocoa

More Related Content

PPTX
An afternoon with angular 2
PDF
Meetup dpjs react_api
PDF
Lecture 2: ES6 / ES2015 Slide
PPTX
Chatbots with Serverless
PPT
Version Control ThinkVitamin
PDF
[React Native Tutorial] Lecture 6: Component, Props, and Network
PDF
[React-Native Tutorial] Lecture 8: Midterm Exam Discussion, Feedback, and Ter...
PPTX
React gsg presentation with ryan jung & elias malik
An afternoon with angular 2
Meetup dpjs react_api
Lecture 2: ES6 / ES2015 Slide
Chatbots with Serverless
Version Control ThinkVitamin
[React Native Tutorial] Lecture 6: Component, Props, and Network
[React-Native Tutorial] Lecture 8: Midterm Exam Discussion, Feedback, and Ter...
React gsg presentation with ryan jung & elias malik

What's hot (20)

PPTX
Going Serverless with OpenWhisk
PDF
RBC Mod 1: Making a New Rails App
PDF
Intro to javascript (4 week)
PDF
Dynamically Composing Collection Operations through Collection Promises
KEY
Lwrp presentation
PDF
Reacting to the Isomorphic Buzz
PDF
Reflection in Pharo: Beyond Smalltak
PDF
2016 - Easing Your Way Into Docker: Lessons From a Journey to Production
PDF
Vasyl Sydorivskiy - Angular Functional Style
ODP
Scal`a`ngular - Scala and Angular
ODP
Drilling the Async Library
PPT
Recovering the Behaviour of AJAX Applications
PPTX
Continuous Delivery with Elastic Beanstalk And CodePipeline on AWS
PPTX
03 spring cloud eureka service discovery
PDF
One does not simply "Upgrade to Rails 3"
PDF
Converting LotusScript Agents to Java Agents
PDF
Threading Made Easy! A Busy Developer’s Guide to Kotlin Coroutines
PDF
AWS Lambda Function with Kotlin
PDF
Introduction to akka actors with java 8
PDF
The future of paas is serverless
Going Serverless with OpenWhisk
RBC Mod 1: Making a New Rails App
Intro to javascript (4 week)
Dynamically Composing Collection Operations through Collection Promises
Lwrp presentation
Reacting to the Isomorphic Buzz
Reflection in Pharo: Beyond Smalltak
2016 - Easing Your Way Into Docker: Lessons From a Journey to Production
Vasyl Sydorivskiy - Angular Functional Style
Scal`a`ngular - Scala and Angular
Drilling the Async Library
Recovering the Behaviour of AJAX Applications
Continuous Delivery with Elastic Beanstalk And CodePipeline on AWS
03 spring cloud eureka service discovery
One does not simply "Upgrade to Rails 3"
Converting LotusScript Agents to Java Agents
Threading Made Easy! A Busy Developer’s Guide to Kotlin Coroutines
AWS Lambda Function with Kotlin
Introduction to akka actors with java 8
The future of paas is serverless
Ad

Similar to Reactive Cocoa Lightning Talk (20)

PDF
Reactive cocoa cocoaheadsbe_2014
PDF
An Introduction to Reactive Cocoa
PDF
Reactive cocoa
PDF
Functional Reactive Programming (CocoaHeads Bratislava)
PPT
Lviv MD Day 2015 Павло Захаров "Reactive cocoa: paradigm shift"
PDF
Reactive cocoa made Simple with Swift
PPT
Reactive cocoa
PDF
Intro to ReactiveCocoa
PDF
Reactive Cocoa
PDF
Learn You a ReactiveCocoa for Great Good
PDF
ReactiveCocoa in Practice
PDF
Hello, ReactorKit 
PDF
Stanfy MadCode Meetup #11: Why do you need to switch from Obj-C to Swift, or ...
PDF
Reactive cocoa
PDF
ReactiveCocoa - Functional Reactive Programming concepts in iOS
PDF
«ReactiveCocoa и MVVM» — Николай Касьянов, SoftWear
PDF
Functional Reactive Programming
PDF
Introduction to reactive programming & ReactiveCocoa
PDF
Reactive Thinking in iOS Development - Pedro Piñera Buendía - Codemotion Amst...
PDF
ReactiveCocoa and Swift, Better Together
Reactive cocoa cocoaheadsbe_2014
An Introduction to Reactive Cocoa
Reactive cocoa
Functional Reactive Programming (CocoaHeads Bratislava)
Lviv MD Day 2015 Павло Захаров "Reactive cocoa: paradigm shift"
Reactive cocoa made Simple with Swift
Reactive cocoa
Intro to ReactiveCocoa
Reactive Cocoa
Learn You a ReactiveCocoa for Great Good
ReactiveCocoa in Practice
Hello, ReactorKit 
Stanfy MadCode Meetup #11: Why do you need to switch from Obj-C to Swift, or ...
Reactive cocoa
ReactiveCocoa - Functional Reactive Programming concepts in iOS
«ReactiveCocoa и MVVM» — Николай Касьянов, SoftWear
Functional Reactive Programming
Introduction to reactive programming & ReactiveCocoa
Reactive Thinking in iOS Development - Pedro Piñera Buendía - Codemotion Amst...
ReactiveCocoa and Swift, Better Together
Ad

Recently uploaded (20)

PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPT
Teaching material agriculture food technology
PPTX
Big Data Technologies - Introduction.pptx
PDF
Encapsulation theory and applications.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
KodekX | Application Modernization Development
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Teaching material agriculture food technology
Big Data Technologies - Introduction.pptx
Encapsulation theory and applications.pdf
Encapsulation_ Review paper, used for researhc scholars
Network Security Unit 5.pdf for BCA BBA.
MIND Revenue Release Quarter 2 2025 Press Release
sap open course for s4hana steps from ECC to s4
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
KodekX | Application Modernization Development
NewMind AI Weekly Chronicles - August'25 Week I
Spectral efficient network and resource selection model in 5G networks
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Advanced methodologies resolving dimensionality complications for autism neur...
Digital-Transformation-Roadmap-for-Companies.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”

Reactive Cocoa Lightning Talk

  • 1. ReactiveCocoa Bob Spryn LoHi Labs @sprynmr (github, twitter) ! ! ! https://github.com/ReactiveCocoa/ReactiveCocoa
  • 2. ReactiveCocoa • An implementation of functional reactive programming • It provides APIs for composing and transforming streams of values • “Signals” send you these values over time for you to react to http://en.wikipedia.org/wiki/Functional_reactive_programming
  • 3. ?
  • 4. Not just another API. It enables you to Program Smarter Focus on WHAT not HOW
  • 6. • Setup your reactions • Compose, Reactive!!! Declarative!!! split, filter, etc. What does that even mean?
  • 7. Imperative The way we normally program.
  • 8. Imperative The way we normally program. • Observe, wait, then command & control • Dealing with the HOW, not just the WHAT • Code for controlling flow is spread all over
  • 9. Auto-layout : Managing Frames ReactiveCocoa : Imperative programming
  • 11. BOOL loadingNextPageOfComments; 2 states BOOL commentsAreShowing; 4 states BOOL commentsLoadingShowing; 8 states BOOL flippingAnswers; 16 states BOOL isOwnerOfQuestion; 32 states
  • 12. - (void) updateChangeAnswerButtonText { if (self.didAnswerQuestion && self.inResultsView) { [self.commentHeaderCell configureWithStyle:TCQuestionDetailCommentHeaderCellChangeAnswer]; } else if (self.isOwnerOfQuestion && !self.didAnswerQuestion && self.inResultsView) { [self.commentHeaderCell configureWithStyle:TCQuestionDetailCommentHeaderCellViewAnswers]; } else { [self.commentHeaderCell configureWithStyle:TCQuestionDetailCommentHeaderCellViewStats]; } } - (void) updateViewCommentStatus { if ((self.didAnswerQuestion || self.isOwnerOfQuestion) && !self.commentsAreShowing) { self.commentsAreShowing = YES; - (void) prepareForReuse { self.commentsLoadingShowing = YES; self.state = TCQuestionDetailViewContro … self.questionFullyLoaded = NO; } self.isOwnerOfQuestion = NO; self.didAnswerQuestion = NO; [self showCommentBox:self.inResultsView || self.isOwnerOfQuestion]; [self showCommentBox:NO]; } self.loadingNextPageOfComments = NO; self.commentsAreShowing = NO; self.commentsLoadingShowing = NO; ! ^aBlock { sself.didAnswerQuestion = sself.question.userResponse ? YES : NO; sself.inResultsView = sself.didAnswerQuestion || self.isOwnerOfQuestion; if (sself.questionFullyLoaded) { return; } … } } l co Rea rom ef d file one
  • 13. ReactiveCocoa to the Rescue! • Signals instead of mutable variables • RACSignal – Think of it as a beacon sending out new values to it’s subscribers
  • 14. RACSignal • A unified interface for observing and reacting to all kinds of events and their values • UI Action • Async Network Call • KVO • Async Processing t’s I in ll a t! pu
  • 15. RACSignal • Shared vocabulary for transforming the received values • • Combine, filter, reduce, map, and many more operations Eventually generate output (side effects) • Updating a label • Update an array with objects from the network • etc.
  • 16. - (void)viewDidLoad {
 [super viewDidLoad];
 [self.username
 addTarget:self
 action:@selector(textFieldTextDidChange:)
 forControlEvents:UIControlEventAllEditingEvents];
 [self.email
 addTarget:self
 action:@selector(textFieldTextDidChange:)
 forControlEvents:UIControlEventAllEditingEvents];
 Your name Your email address Sign Up abled ton.en ut gnUpB si } ! - (void)textFieldTextDidChange:(UITextField *)field {
 BOOL validUsername = self.username.text.length > 0;
 
 NSRange at = [self.email.text rangeOfString:@"@"];
 
 BOOL validEmail = at.location != NSNotFound;
 self.signupButton.enabled = validUsername &&
 validEmail;
 } Old Solved the imperative way.
  • 17. Your name Your email address RAC(self.signUpButton, enabled) = [RACSignal combineLatest:@[
 self.name.rac_textSignal,
 self.email.rac_textSignal
 ]
 reduce:^(NSString *name, NSString *email) {
 NSRange at = [email rangeOfString:@"@"]; return @(at.location != NSNotFound && name.length > 0);
 }]; Sign Up ould I Sh SOME AWE bled? e ena b Solved the reactive way.
  • 18. Your name Your email address RAC(self.signUpButton, enabled) = [RACSignal combineLatest:@[
 self.name.rac_textSignal,
 self.email.rac_textSignal
 ]
 reduce:^(NSString *name, NSString *email) {
 NSRange at = [email rangeOfString:@"@"]; return @(at.location != NSNotFound && name.length > 0);
 }]; Sign Up ould I Sh SOME AWE bled? e ena b Solved the reactive way.
  • 19. Network Validation? Easy. Your name Your email address Sign Up RACSignal *validateEmailSignal = [self.email.rac_textSignal map:^id(NSString *emailString) { return [MyAPI validatedEmail:emailString]; }]; uld I Sho bled? be ena ! RAC(self.signUpButton, enabled) = [RACSignal combineLatest:@[
 self.name.rac_textSignal,
 validateEmailSignal
 ]
 reduce:^(NSString *name, APIResponse *response) {
 return @(response.json.isValid == YES && name.length > 0);
 }]; SOME AWE Solved the reactive way.
  • 20. Network Validation? Easy. Your name Your email address Sign Up RACSignal *validateEmailSignal = map }]; ! uld I Sho The point is to Minimize State RAC combineLatest ] reduce }]; Solved the SOME AWE bled? be ena
  • 21. Network Validation? Easy. Your name Your email address Sign Up RACSignal *validateEmailSignal = map }]; ! uld I Sho The point is to Minimize State RAC combineLatest ] reduce }]; Solved the SOME AWE bled? be ena
  • 22. Check out ReactiveCocoa Your Brain Will Thank You https://github.com/ReactiveCocoa/ReactiveCocoa Bob Spryn LoHi Labs @sprynmr (github, twitter) ! Thanks to @jspahrsummers, @joshaber, @AshFurrow, @robb, @andrewsardone and @erikprice (github usernames) for sharing their presentation slides and helping me learn ReactiveCocoa