ReactiveCocoa v4.0 Release Notes
-
If youβre new to the Swift API and migrating from RAC 2, start with the 3.0 changes. This section only covers the differences between
3.0
and4.0
.Just like in
RAC 3
, because Objective-C is still in widespread use, 99% ofRAC 2.x
code will continue to work underRAC 4.0
without any changes. That is,RAC 2.x
primitives are still available inRAC 4.0
.ReactiveCocoa 4.0
targets Xcode 7.2.x and Swift 2.1.x, and it supportsiOS 8.0
,watchOS 2.0
,tvOS 9.0
andOS X 10.9
.π¦ Signal operators are protocol extensions
The biggest change from
RAC 3
toRAC 4
is thatSignal
andSignalProducer
operators are implemented as protocol extensions instead of global functions. This is similar to many of the collection protocol changes in theSwift 2
standard library.π¦ This enables chaining signal operators with normal dot-method calling syntax, which makes autocompleting operators a lot easier. Previously the custom
|>
was required to enable chaining global functions without a mess of nested calls and parenthesis./// RAC 3 signal |> filter { $0 % 2 == 0 } |> map { $0 * $0 } |> observe { print($0) } /// RAC 4 signal .filter { $0 % 2 == 0 } .map { $0 * $0 } .observeNext { print($0) }
β Additionally, this means that
SignalProducer
operators are less βmagicβ. In RAC 3 theSignal
operators were implicitly lifted to work onSignalProducer
via|>
. This was a point of confusion for some, especially when browsing the π¦ source looking for these operators. Now as protocol extensions, theSignalProducer
operators are explicitly implemented in terms of theirSignal
counterpart when available.Removal of
|>
custom operatorπ¦ As already alluded to above, the custom
|>
operator for chaining signals has been removed. Instead standard method calling syntax is used for chaining operators.Event cases are no longer boxed
π The improvements to associated enum values in
Swift 2
mean thatEvent
case no longer need to beBox
ed. In fact, theBox
dependency has been removed completely fromRAC 4
.Replacements for the
start
andobserver
overloadsπ The
observe
andstart
overloads takingnext
,error
, etc. optional function parameters have been removed. Theyβve been replaced with methods taking a single function with π the targetEvent
case βobserveNext
,startWithNext
, and the same forfailed
andcompleted
. See #2311 and #2318 for more details.π Renamed
try
andcatch
operatorsThe
try
andcatch
operators were renamed because of the addition of the error handling keywords with the same name. They are nowattempt
andflatMapError
respectively. Also,tryMap
was renamed toattemptMap
for consistency.π¦
flatten
andflatMap
are now possible for all 4 combinations ofSignal
+SignalProducer
π¦ This fills a gap that was missing in
RAC 3
. Itβs a common pattern to have signals-of-signals or signals-of-producers. π¦ The addition offlatten
andflatMap
over these makes it now possible to work with any combination ofSignal
s andSignalProducer
s.π Renamed
Event.Error
toEvent.Failed
π¦ The
Error
case ofEvent
has changed toFailed
. This aims to help clarify the terminating nature of failure/error events and puts them in the same tense as other terminating cases (Interrupted
andCompleted
). Likewise, some operations and parameters have been renamed (e.g.Signal.observeError
is nowSignal.observeFailed
,Observer.sendError
is nowObserver.sendFailed
).π¦ Renamed signal generic parameters
π¦ The generic parameters of
Signal
,SignalProducer
, and other related types have been renamed toValue
andError
fromT
andE
respectively. This is in-line with changes to the standard library to give more descriptive names to type parameters for increased clarity. This should have limited impact, π¦ only affecting generic, custom signal/producer extensions.β Added missing
SignalProducer
operatorsπ¦ There were some
Signal
operators that were missingSignalProducer
equivalents:takeUntil
- β
combineLatestWith
sampleOn
takeUntilReplacement
zipWith
β Added new operators:
- π¦
Signal.on
. - π¦
Signal.merge(signals:)
. - π¦
Signal.empty
. skipUntil
.replayLazily
(#2639).
π Renamed
PropertyOf<T>
toAnyProperty<T>
This is in-line with changes to the standard library in
Swift 2
.β¨ Enhancements to
PropertyType
MutableProperty
received 3 new methods, similar to those inAtomic
:modify
,swap
, andwithValue
. β Additionally, allPropertyType
s now have asignal: Signal<T>
in addition to their existingproducer: SignalProducer<T>
property.Publicized
Bag
andAtomic
Bag
andAtomic
are now public. These are useful when creating custom operators for RAC types.π¦
SignalProducer.buffer
no longer has a default capacityπ¦ In order to force users to think about the desired capacity, this no longer defaults to
Int.max
. Prior to this change one could have inadvertently cached every value emitted by theSignalProducer
. This needs to be specified manually now.β Added
SignalProducer.replayLazily
for multicastingπ¦ Itβs still recommended to use
SignalProducer.buffer
orPropertyType
when buffering behavior is desired. However, when you need to compose an existingSignalProducer
to avoid duplicate side effects, this operator is now available.π The full semantics of the operator are documented in the code, and you can see #2639 for full details.