Slug agnes cover 2?fm=jpg&fl=progressive&q=75&w=300

Beer Brewing App with FRP & Swift 2

We don’t often get to try the hottest new technologies and learn new skills when pressed for time or under projects constraints. In this talk, Agnes Vasarhelyi discusses how side projects allow her to do just that, and walks us through her experience building Brewfactory. Assisting in homebrewing beer, the iOS app gave her the opportunity to try out Functional Reactive Programming, Swift 2, and more!

Hi everyone, my name is Agnes Vasarhelyi (@vasarhelyia), and I work for Prezi as a Mac developer. Prezi is a cloud-based presentations tool with a zooming UI.

Prezi Technology (0:36)

Prezi started with Objective-C for our Mac app. When I joined this team a year ago, I got introduced to a lot of cool technologies. For example, we use Typhoon for dependency injection, Kiwi for testing and ReactiveCocoa for everything. If you are not familiar with ReactiveCocoa, it’s a functional reactive programming framework for iOS and Mac. Although it gave me a hard time at the beginning, I ended up falling in love with it.

Frameworks in Brewfactory for iOS (1:28)

To get back into iOS development, I joined an open source project called Brewfactory which is an automated brewing system, and my idea was to experiment with cool technologies on this project, too. I’m using for communication with the backend, Specta/Expecta for testing, and I was building with Travis CI in the beginning.

Get more development news like this

The iOS app is fairly simple with two primary features. The BrewViewController is for supervising your brewing process, using WebSocket communication with a Node.js backend. The other BrewDesignerViewController is for composing a brew, and syncing it with the backend with an HTTP POST. The whole idea is “how cool would it be to control your brewing from your iPhone?” This simple MVC app just worked, but what’s the fun in that?

I wanted to try something new, and around that time React Native was released. React Native makes it possible to write JavaScript and use React on iOS, rendering native UIKit elements, which is incredible. At the time, it was in a phase when all these React Native components were missing and needed to be written in the native language, like a polyfill for the functionality. We could help the community and do that for them. In case of Brewfactory, it wasn’t quite what I was looking for.

Reactive Programming and Swift (4:05)

During my daily work I developed some interest in reactive programming. It’s really a hot topic right now as everybody’s looking for a better developer experience, especially in the field of iOS and Mac. Reactive programming is async, data-driven programming, which can help turn your imperative code into reactive code, which makes your code simpler and much better.

Then Swift happened, and I was thinking why not do both? I re-implemented this whole app in Swift and with reactive programming. I also updated the tooling and replaced CocoaPods with Carthage. It was just for fun, but I’ve been using it since everywhere. We also started using Bitrise, which is a new CI for iOS. I had some problems with Travis, with all our beta dependencies, so I replaced it with Bitrise and it worked better.

Model-View-ViewModel (MVVM) (5:34)

The first thing I had to do to support this architecture was replace my MVC architecture with MVVM. If you are transforming an app, it means that you turn your controllers to views and push the bindings to the view model, which is a new layer.

This was necessary since I had some problems with MVC. I felt that I had a messy view and some models, and everything else in the view controller. After making this change, object responsibilities became clearer and the codebase worked better with testing.

ReactiveCocoa (6:42)

Next I wanted to add ReactiveCocoa to the project. I already used it with Objective-C, so I was familiar with the API and use to it. It was compatible with Swift in a way that it had a thin Swift interface, so you could reach the same functionality that you could reach from the Objective-C code. The experience was that half of my code was gone, which is impressive and the quality and the simplicity was much better. At the same time, it was really hard to find new contributors, of course.

In the meantime, the ReactiveCocoa team was working on a Swift API which had conceptual changes so I read the documentation for weeks and tried to understand new concepts such as the separation of hot and cold signals. UI key bindings were also missing.

When I started with Release Candidate One, I had to do some workarounds with the Objective-C bridging, but it was possible.

Swift 2 (8:26)

Swift 2 came out recently with a lot of cool features like protocol extensions, try/catch and some improved language features all of which improve readability. This made ReactiveCocoa take a major step forward again, increasing its usability. There was some kind of pipe operator which was a bit annoying to use all the time, and with these protocol extensions they could replace it with simple basic dot notation.

It’s still a work in progress alpha with breaking changes, but it will be great once finalized.

What’s Next? (9:40)

Besides brewing lots of beer, I have two promising projects on my map. The first one is RxSwift, the official reactive extension for Swift. The other is vincerp, which is being developed by a friend of mine, and will be released in a few weeks, so I’m going to give it a try. If you are interested in those, I will write a post in my blog about these experiments of mine. Thank you, that’s all.

About the content

This content has been published here with the express permission of the author.

Agnes Vasarhelyi

Agnes Vasarhelyi is an iOS developer at Ustream. She likes to build up software from streams of values and automate things in the meantime. Her blog tells you about reactive programming and her tweets about organizing community events.

4 design patterns for a RESTless mobile integration »