This document provides an overview of ReactiveCocoa, a framework for functional reactive programming (FRP) in iOS and OSX. It discusses the core concepts in FRP like signals that send values over time, and how functions can transform signal values without side effects. ReactiveCocoa uses signals as the primary data source, and provides methods like map, filter and reduce to transform signal values in a functional way. It also explains how bindings in ReactiveCocoa can link properties to signal values to update the UI automatically. The document compares MVC and MVVM patterns, and provides a code example of using ReactiveCocoa signals and bindings in a view model.
6. Functional Programming
¡ñ Lambda Calculus
¡ñ Functions without side effects
¡ñ Programs as function
compositions (y = f(g(h(x))))
7. Functional Reactive Programming
¡ñ In functional programming, things get hard
because functions can¡¯t have side-effects
o Every time a function is called, it must
return the same y for same x
o y = f(x)
¡ñ In functional reactive programming, time is
an implicit parameter (no monads)
o y = f(x, t)
8. ReactiveCocoa
¡ñ A open source FRP framework developed
by Github
o iOS / OSX
o MIT License
o 3.0 supports swift
o https://github.com/ReactiveCocoa/Reacti
veCocoa
9. Signals
¡ñ Primary data source of FRP
¡ñ Signals send values over time until they
complete
o A signal never sends anything after
completing or erring
o A signal either completes, or errors out,
but never both
10. Signals(cont.)
¡ñ A signal has no concept of a ¡°current
value¡± or ¡°past value¡±
¡ñ It¡¯s like a pipe
¡ñ Signals can be chained to transform the
values
o This is core to FRP: data transformation
of values sent over time
o y = f(g(h(x)))
15. Map
¡ñ Mapping performs a value transformation
on the given signal
o It ¡±maps¡± each value sent along the
signal to a new value
o It then passes that new value along,
creating a new signal
23. Bindings
¡ñ Bindings can bind a property to the latest
value sent on a signal
¡ñ All bindings created with the RAC macro
are one-way
¡ñ Bindings are the secret sauce that hold
apps together
27. MVC (Model View Controller)
? Pros :
? Independent module
? Reusable model
? Cons:
? too may files
? hard to write unit test
? controller need to access view&model
27
30. MVVM(Model View ViewModel)
? Pros:
? ViewModel can be unit tested
? ViewModel has no access to view
? Model has no access to ViewModel
? View is simple
? UI logic moved to ViewModel
? Cons:
? hard to debug
? performance hit!!! 30