SlideShare a Scribd company logo
An Introduction to
Reactive Cocoa
Ara Hacopian
BohConf
July 2013
Ara Hacopian
www.smartlogic.io
twitter.com/ahacop
github.com/ahacop
SmartLogic
What is Reactive Cocoa?
RAC is an Objective-C framework for
Functional Reactive Programming
Reactive Programming?
A programming paradigm oriented around
data flows and propagation of change.
Imperative
int x, y = 1, z = 1;
x = y + z; // x = 2; y = 1; z = 1;
y = 3; // x = 2; y = 3; z = 1;
NSLog(@"%d", x); // "2"
Reactive
int x, y = 1, z = 1;
x = y + z; // x = 2; y = 1; z = 1;
y = 3; // x = 4; y = 3; z = 1;
NSLog(@"%d", x); // "4"
We have this: KVO
// In your viewDidLoad/awakeFromNib/init
[self addObserver:self
forKeyPath: @"someString"
options:NSKeyValueObservingOptionNew
context:&someStringChangeContext];
// In dealloc
[self removeObserver: self
forKeyPath: @"someString"
context:&someStringChangeContext];
// Elsewhere in your class
- (void)observeValueForKeyPath:( NSString *)keyPath
ofObject:( id)object
change:( NSDictionary *)change
context:( void *)context
{
if (context == &someStringChangeContext) {
if ([keyPath isEqualToString: @"someString"]) {
// Do a bunch of stuff here
}
}
}
Do it in RAC
[RACAble(self.someString) distinctUntilChanged]
subscribeNext:^(NSString *string) {
// Do a bunch of things here, just like you would with KVO
}];
Source: http://tonyarnold.me/post/reactivelessons
Streams
A series of object values.
● Accessed sequentially.
● Available immediately or in the future.
● Allow for declarative transforms
Two types:
1. Signals
2. Sequences
Sequence
A pull-driven stream.
● Lazily evaluated collections
Sequence Example
// words = @[ NSArray containing words ]
RACSequence *normalizedLongWords =
[[words.rac_sequence
filter:^ BOOL (NSString *word) {
return [word length] >= 10;
}]
map:^(NSString *word) {
return [word lowercaseString];
}];
Signal
A push-driven stream.
● Generally represents data that will be
delivered in the future.
● Values are sent on the signal
● Users subscribe to access values
3 types of events sent to subscribers:
1. Next - provides next value
2. Error
3. Completed
Signal Example
[self.textField.rac_textSignal
subscribeNext:^(NSString *value) {
NSLog(@"Text field updated: %@",
value);
}];
Signal Example 2
[[self.textField.rac_textSignal
filter:^BOOL(NSString *value) {
return [value length] >= 3;
}]
subscribeNext:^(NSString *value) {
NSLog(@"Text field updated: %@",
value);
}];
An Introduction to Reactive Cocoa
RACSignal *formValid = [RACSignal
combineLatest:@[
self.userNameField.rac_textSignal,
self.emailField.rac_textSignal,
self.confirmEmailField.rac_textSignal,
]
reduce:^(NSString *userName, NSString *email,
NSString *confirmEmail) {
return @(username.length > 0
&& email.length > 0
&& confirmEmail.length > 0
&& [email isEqualToString:confirmEmail]);
}];
RAC(self.createAccountBtn.enabled) = formValid;
RACCommand
self.loginCommand = [RACCommand command];
self.loginSignals = [self.loginCommand
addSignalBlock:^(id sender) {
return [client logIn];
}];
[self.loginSignals subscribeNext:^(RACSignal
*loginSignal) {
[loginSignal subscribeCompleted:^(id _) {
NSLog(@"Logged in successfully!");
}];
}];
self.loginBtn.rac_command = self.loginCommand;
Resources
https://github.com/ReactiveCocoa/ReactiveCocoa
https://pinboard.in/u:andrewsardone/t:ReactiveCocoa
Questions?
http://www.smartlogic.io
http://www.twitter.com/smartlogic
http://www.github.com/smartlogic
http://www.facebook.com/smartlogic

More Related Content

PDF
Reactive cocoa made Simple with Swift
PDF
ReactiveCocoa and Swift, Better Together
PDF
ReactiveCocoa in Practice
PDF
Learn You a ReactiveCocoa for Great Good
PDF
Intro to ReactiveCocoa
PDF
ReactiveCocoa Goodness - Part I of II
PDF
Introduction to reactive programming & ReactiveCocoa
PDF
Introduction to RxJS
Reactive cocoa made Simple with Swift
ReactiveCocoa and Swift, Better Together
ReactiveCocoa in Practice
Learn You a ReactiveCocoa for Great Good
Intro to ReactiveCocoa
ReactiveCocoa Goodness - Part I of II
Introduction to reactive programming & ReactiveCocoa
Introduction to RxJS

What's hot (20)

PDF
My Gentle Introduction to RxJS
PDF
Swift Sequences & Collections
PDF
Angular and The Case for RxJS
PDF
Reactive Programming for a demanding world: building event-driven and respons...
PDF
Wrapping java in awesomeness aka condensator
PPTX
Luis Atencio on RxJS
ODP
Functional programming in Javascript
PPTX
PPTX
Reactive Java (33rd Degree)
PDF
Cocoa heads 09112017
PDF
Monads in Swift
PDF
Reactive Programming Patterns with RxSwift
PDF
Talk KVO with rac by Philippe Converset
PDF
Swift & ReactiveX – Asynchronous Event-Based Funsies with RxSwift
PPTX
Functional Reactive Programming (FRP): Working with RxJS
PDF
Oop assignment 02
PDF
Map kit light
PDF
Advanced functional programing in Swift
PDF
Intro to RxJava/RxAndroid - GDG Munich Android
PDF
Callbacks and control flow in Node js
My Gentle Introduction to RxJS
Swift Sequences & Collections
Angular and The Case for RxJS
Reactive Programming for a demanding world: building event-driven and respons...
Wrapping java in awesomeness aka condensator
Luis Atencio on RxJS
Functional programming in Javascript
Reactive Java (33rd Degree)
Cocoa heads 09112017
Monads in Swift
Reactive Programming Patterns with RxSwift
Talk KVO with rac by Philippe Converset
Swift & ReactiveX – Asynchronous Event-Based Funsies with RxSwift
Functional Reactive Programming (FRP): Working with RxJS
Oop assignment 02
Map kit light
Advanced functional programing in Swift
Intro to RxJava/RxAndroid - GDG Munich Android
Callbacks and control flow in Node js
Ad

Similar to An Introduction to Reactive Cocoa (20)

PPT
Lviv MD Day 2015 Павло Захаров "Reactive cocoa: paradigm shift"
PPT
Reactive cocoa
PDF
DZone_RC_RxJS
PPTX
Apple.combine
PDF
Reactive programming and RxJS
PDF
Building Scalable Stateless Applications with RxJava
PDF
JavaScript(Es5) Interview Questions & Answers
PPTX
4Developers 2015: Programowanie synchroniczne i asynchroniczne - dwa światy k...
PDF
RxJava@DAUG
PDF
Reactive cocoa cocoaheadsbe_2014
PPTX
JavaScript.pptx
PPTX
Java script
ODP
Functional programming with Scala
PPTX
Functional Reactive Endpoints using Spring 5
PPTX
Introduction to RxJS
PPTX
js.pptx
PPTX
Data visualization in python/Django
PDF
JavaScript Editions ES7, ES8 and ES9 vs V8
PPT
PDF
Demystifying Reactive Programming
Lviv MD Day 2015 Павло Захаров "Reactive cocoa: paradigm shift"
Reactive cocoa
DZone_RC_RxJS
Apple.combine
Reactive programming and RxJS
Building Scalable Stateless Applications with RxJava
JavaScript(Es5) Interview Questions & Answers
4Developers 2015: Programowanie synchroniczne i asynchroniczne - dwa światy k...
RxJava@DAUG
Reactive cocoa cocoaheadsbe_2014
JavaScript.pptx
Java script
Functional programming with Scala
Functional Reactive Endpoints using Spring 5
Introduction to RxJS
js.pptx
Data visualization in python/Django
JavaScript Editions ES7, ES8 and ES9 vs V8
Demystifying Reactive Programming
Ad

More from SmartLogic (20)

PDF
Writing Game Servers with Elixir
PDF
All Aboard The Stateful Train
PDF
DC |> Elixir Meetup - Going off the Rails into Elixir - Dan Ivovich
PDF
Monitoring Your Elixir Application with Prometheus
PDF
Going Multi-Node
PPTX
Kubernetes and docker
PDF
Serializing Value Objects-Ara Hacopian
PDF
Guide to food foraging by SmartLogic's Kei Ellerbrock
PDF
Introduction to Type Script by Sam Goldman, SmartLogic
PDF
How SmartLogic Uses Chef-Dan Ivovich
PPTX
A Few Interesting Things in Apple's Swift Programming Language
PDF
Effective ActiveRecord
PDF
iOS Development Methodology
PPT
CSS Preprocessors to the Rescue!
PDF
Deploying Rails Apps with Chef and Capistrano
PDF
From Slacker to Hacker, Practical Tips for Learning to Code
PDF
The Language of Abstraction in Software Development
PDF
Android Testing: An Overview
PPTX
Intro to DTCoreText: Moving Past UIWebView | iOS Development
PDF
Logstash: Get to know your logs
Writing Game Servers with Elixir
All Aboard The Stateful Train
DC |> Elixir Meetup - Going off the Rails into Elixir - Dan Ivovich
Monitoring Your Elixir Application with Prometheus
Going Multi-Node
Kubernetes and docker
Serializing Value Objects-Ara Hacopian
Guide to food foraging by SmartLogic's Kei Ellerbrock
Introduction to Type Script by Sam Goldman, SmartLogic
How SmartLogic Uses Chef-Dan Ivovich
A Few Interesting Things in Apple's Swift Programming Language
Effective ActiveRecord
iOS Development Methodology
CSS Preprocessors to the Rescue!
Deploying Rails Apps with Chef and Capistrano
From Slacker to Hacker, Practical Tips for Learning to Code
The Language of Abstraction in Software Development
Android Testing: An Overview
Intro to DTCoreText: Moving Past UIWebView | iOS Development
Logstash: Get to know your logs

Recently uploaded (20)

PPTX
1. Introduction to Computer Programming.pptx
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
August Patch Tuesday
PPTX
Machine Learning_overview_presentation.pptx
PPTX
Tartificialntelligence_presentation.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Empathic Computing: Creating Shared Understanding
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
1. Introduction to Computer Programming.pptx
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Programs and apps: productivity, graphics, security and other tools
Advanced methodologies resolving dimensionality complications for autism neur...
Univ-Connecticut-ChatGPT-Presentaion.pdf
cloud_computing_Infrastucture_as_cloud_p
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Encapsulation_ Review paper, used for researhc scholars
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
August Patch Tuesday
Machine Learning_overview_presentation.pptx
Tartificialntelligence_presentation.pptx
MIND Revenue Release Quarter 2 2025 Press Release
Empathic Computing: Creating Shared Understanding
Reach Out and Touch Someone: Haptics and Empathic Computing
Network Security Unit 5.pdf for BCA BBA.
A comparative study of natural language inference in Swahili using monolingua...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025

An Introduction to Reactive Cocoa