This article is a follow-up for my previous piece about how to update your app with the new ReactiveCocoa 3.0 Swift API. It has been released a few weeks ago, but Swift 2 already happened since, so the time has come to step a major version forward. Here we go, 4.0 alpha 2!
I did the same with BrewMobile, the pet project I'm trying out new stuff with, let's see how things look like now with Swift 2 & ReactiveCocoa 4.0.
There are a few things to setup in advance.
Let's check out the
github "ReactiveCocoa/ReactiveCocoa" "v4.0.0-alpha.2"
if you experience errors during your
carthage updatejust clean your DerivedData and shoot:
carthage update --platform iOS --no-use-binaries
Making sure it won't use cached versions from the pre-built frameworks like RAC itself.
Edit>Convert>To The Latest Swift Syntax and let it do it's magic, it helps to avoid some boring refactoring minutes.
It's time to update the code using ReactiveCocoa to the latest & greatest. I suggest to read the change log first, that's always up-to-date.
. is the new |>
Since they turned Signal and SignalProducer operators into protocol extensions (which is really cool), it became possible to drop the global function setup and use dot notation for chaining the operators. Hence I started with replacing the pipe (
|>) operators with the good old dot notation syntax.
catch going flatMapError
Another change was to replace
flatMapError everywhere, since
catch became reserved with in Swift 2.
.value instead of put()
Although these are indicated to likely being changed again in later versions, it is important to check out the changes of
With the Swift 2 parts, I faced several issues after the automatic Xcode conversion, besides some minor improvements like
count as a property on
With the original error handling approaches gone, error arguments became extra in the new Swift 2 compiler. We have
Xcode will kindly ask you to replace HTTP requests with a secure one (it won't work otherwise). Although it is possible to whitelist insecure URLs in the app's
About & more
Please note, these changes were the necessary ones, there is so much more you can improve in your code with Swift 2.0 and ReactiveCocoa 4.0 as well. If you find something in BrewMobile you would definitely make better, just add a comment below (or a PR on GitHub).