Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Reactive Cocoa e MVVM
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Guilherme Martinez Sampaio
October 30, 2014
Programming
1
100
Reactive Cocoa e MVVM
Palestra dada no CocoaHeads CPS Outubro/2013
Guilherme Martinez Sampaio
October 30, 2014
Tweet
Share
More Decks by Guilherme Martinez Sampaio
See All by Guilherme Martinez Sampaio
CocoaPods: Gerenciador de Dependência para iOS e Mac
gsampaio
0
78
Other Decks in Programming
See All in Programming
高速開発のためのコード整理術
sutetotanuki
1
400
AI Schema Enrichment for your Oracle AI Database
thatjeffsmith
0
290
Smart Handoff/Pickup ガイド - Claude Code セッション管理
yukiigarashi
0
140
KIKI_MBSD Cybersecurity Challenges 2025
ikema
0
1.3k
FOSDEM 2026: STUNMESH-go: Building P2P WireGuard Mesh Without Self-Hosted Infrastructure
tjjh89017
0
170
0→1 フロントエンド開発 Tips🚀 #レバテックMeetup
bengo4com
0
570
Honoを使ったリモートMCPサーバでAIツールとの連携を加速させる!
tosuri13
1
180
[KNOTS 2026登壇資料]AIで拡張‧交差する プロダクト開発のプロセス および携わるメンバーの役割
hisatake
0
280
Implementation Patterns
denyspoltorak
0
290
登壇資料を作る時に意識していること #登壇資料_findy
konifar
4
1.2k
LLM Observabilityによる 対話型音声AIアプリケーションの安定運用
gekko0114
2
430
Unicodeどうしてる? PHPから見たUnicode対応と他言語での対応についてのお伺い
youkidearitai
PRO
1
2.5k
Featured
See All Featured
Rebuilding a faster, lazier Slack
samanthasiow
85
9.4k
How To Stay Up To Date on Web Technology
chriscoyier
791
250k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
170
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
350
Are puppies a ranking factor?
jonoalderson
1
2.7k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
Paper Plane (Part 1)
katiecoart
PRO
0
4.2k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.6k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.3k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
66
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
220
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
110
Transcript
INTRODUÇÃO A REACTIVE FUNCTIONAL PROGRAMMING. by Guilherme Martinez Sampaio
Guilherme Martinez Sampaio iOS Developer @gsampaio
None
None
Agenda ▸ Functional Reactive Programming ▸ Reactive Cocoa ▸ Model
View View Model ▸ Demo ▸ Referências
FUNCTIONAL REACTIVE PROGRAMMING?
None
FUNCTIONAL REACTIVE PROGRAMMING IS A PROGRAMMING PARADIGM FOR reactive programming
USING THE BUILDING BLOCKS OF functional programming.
FRP HAS BEEN USED FOR PROGRAMMING GUI, ROBOTICS, AND MUSIC,
AIMING TO SIMPLIFY THESE PROBLEMS BY EXPLICITLY modeling time.
EM OUTRAS PALAVRAS DESCREVEMOS NOSSOS PROGRAMAS COMO EVENTOS QUE REAGEM
COM o tempo
Reactive Cocoa
RAC É FORTEMENTE BASEADA NO RXEXTENSIONS DA MICROSOFT PARA .NET
RAC SE BASEIA EM Signals E Sequences
AO INVÉS DE USAR variáveis QUE SÃO ALTERADAS USAMOS sinais
QUE CAPTURA O valor atual E valores futuros.
SINAIS FUNCIONAM COMO Promises
SINAIS TEM subscribers QUE ESCUTAM SUAS ALTERAÇÕES
SUBSCRIBERS RECEBEM 3 eventos
NEXT
COMPLETED
ERROR
RACSIGNAL __block NSUInteger subscribers = 0; RACSignal *signal = [RACSignal
createSignal:^ RACDisposable * (id<RACSubscriber> subscriber) { subscribers++; [subscriber sendNext:@(subscribers)]; [subscriber sendCompleted]; return nil; }]; [signal subscribeNext:^(id x) { NSLog(@"%@", x) } error:^(NSError *error) { NSLog(@"ERRO !"); } completed:^{ NSLog(@"Signal completo"); }] /** Output: 1 Signal completo **/
SINAIS SÃO EXECUTADOS A A PARTIR DO MOMENTO QUE ELE
TEM UM subscriber ATÉ ELE ENVIAR UM SINAL DE completed
SINAIS PODEM TER VÁRIOS subscribers
PODEMOS COMPOR SINAIS USANDO programação funcional
RACSIGNAL __block NSUInteger subscribers = 2; RACSignal *signal = [RACSignal
createSignal:^ RACDisposable * (id<RACSubscriber> subscriber) { subscribers++; [subscriber sendNext:@(subscribers)]; [subscriber sendCompleted]; return nil; }]; RACSignal *powSingal = [signal map:^NSNumber(NSNumber *value){ NSUInteger intValue = [value unsignedIntegerValue]; return @(intValue * intValue); }]; [signal subscribeNext:^(id x) { NSLog(@"VALUE: %@", x); }]; /** Outputs: 9 **/
COLLECTIONS PODEM GERAR RACSequence QUE POR SUA VEZ PODEMOS USAR
APLICAR Programação Funcional
RACSEQUENCE NSArray *lettersArray = [@"A B C D E F
G H I" componentsSeparatedByString:@" "]; RACSignal *letters = lettersArray.rac_sequence.signal; [letters subscribeNext:^(NSString *x) { NSLog(@"%@", x); }]; /** Outputs: A B C D E F G H I **/
RACSEQUENCE RACSignal *numbers = [@[@(1), @(2), @(3)].rac_sequence.signal; RACSignal *pow =
[numbers map:^NSNumber*(NSNumber *value){ NSUInteger intValue = [value unsignedIntegerValue]; return @(intValue * intValue); }]; [pow subscribeNext:^(NSNumber *value) { NSLog(@"%@", value); }]; /** Outputs: 1 4 9 **/
RAC CONTEM MACROS PARA FAZER data-binding
RAC() @interface ViewController () @property(nonatomic) NSUInteger *foo; @property(nonatomic) NSUInteger *bar;
@end @implementation ViewController - (void)viewDidLoad { self.foo = 0; self.bar = 0; NSLog(@"FOO: %@", @(self.foo)); RAC(self, foo) = RACObserve(self, bar); self.bar = 1; NSLog(@"FOO: %@", @(self.foo)); } @end /** Outputs: FOO: 0 FOO: 1 **/
MVVM
MODEL VIEW VIEW-MODEL É UM ARCHITECTURAL PATTERN SEMELHANTE AO MVC
MODEL VIEW CONTROLLER
MAS NA REALIDADE O QUE ACONTECE É QUE FICAMOS COM
view controllers gigantes
MODEL VIEW CONTROLLER
COM MVVM MOVEMOS A LÓGICA DE NEGOCIO TOTALMENTE FORA DO
VC
E TRATAMOS O VC COMO PARTE DA VIEW UMA VEZ
QUE ELE TRATA APRESENTAÇÃO, ROTAÇÃO E NAVEGAÇÃO.
MODEL VIEW VIEW-MODEL
PARA CADA VIEW CRIAMOS UM VIEW MODEL QUE TRATA ELA.
USAMOS DATA BINDING PARA FAZER COMUNICAÇÃO.
MODEL VIEW VIEW MODEL @interface ViewController () @property(nonatomic, strong) ViewModel
*viewModel; @property(nonatomic, weak) UITextField *textField; @property(nonatomic, weak) UILabel *label; @end @implementation ViewController - (void)viewDidLoad { RAC(self.viewModel, text) = [self.textField rac_textSignal]; RAC(self.label, text) = [self.viewModel expensiveComputation]; } @end
VIEW MODELS facilitam escrever testes de uma view. UMA VEZ
QUE TESTAMOS O COMPORTAMENTO DAS VIEWS AO INVÉS DA VIEW EM SI
VIEW MODELS PREGAM Composição sobre Herança.
FAZENDO COM QUE TENHAMOS UM CÓDIGO mais reaproveitável.
UMA VEZ QUE PODEMOS PLUGAR OS VIEW MODELS QUE QUEREMOS
NOS NOSSOS VC
COM ALGUMA EXCESSÕES VIEW MODELS SÃO independentes de plataforma.
DEMO
REFERÊNCIAS ▸ FRP - http://en.wikipedia.org/wiki/ Functional_reactive_programming ▸ Reactive Cocoa -
https://github.com/ ReactiveCocoa/ReactiveCocoa ▸ Model View View Model - http://www.objc.io/ issue-13/mvvm.html
TWITTER ▸ @jspahrsummers ▸ @joshaber ▸ @rob_rix ▸ @indragie ▸
@ashfurrow
SLIDES E DEMO https://github.com/gsampaio/RACMVVMPresentation
THANKS
None