Lyft Goes Swift: How (And Why) It Rewrote Its App From Scratch In Apple’s New Language

Lyft’s old code was fine. But its new version is tighter, easier to maintain–and ready for the future.

Lyft Goes Swift: How (And Why) It Rewrote Its App From Scratch In Apple’s New Language
[Photos: courtesy of Lyft]

When Apple ended its WWDC keynote in June 2014 by announcing Swift, an all-new language for creating iOS apps, it was an unusual moment for a couple of reasons. For one thing, it was a seriously technical bit of news during a keynote that traditionally addresses consumers as much as it does engineers. For another, Apple had successfully kept Swift secret, making its debut a genuine shocker.

The prospect of a modern programming platform designed with iOS in mind got plenty of developers excited. But it also raised questions. How easy would it be to recreate apps written in Objective-C, the existing standard for iOS development? Would the benefits of working in a more up-to-date environment counterbalance the hassle of starting from scratch? If Swift was the future, would it make more sense to dive right in or wait until it was a polished, proven platform?

Among the app developers that wrestled with such issues was Lyft, the San Francisco-based driver-on-demand car service. It thought the matter over, then put one developer on Swift to investigate the situation, and then, in due time, decided to redo its entire application in Swift. A bit over a year after Apple’s announcement, it was ready with an all-Swift version of Lyft. The company believes that it’s the largest app to make the move, both in terms of lines of code and number of users.

“Early on, we regarded this as somewhat of an experiment, and very risky,” says Chris Lambert, the company’s CTO. But by pursuing the project at the right pace, it ended up with a version of the app that made its developers far more productive and happy–and which performed just like the old one, right out of the gate.

Out With The Old

In a way, it’s remarkable that Apple waited until 2014 to unveil something like Swift. Objective-C originated in the early 1980s, long before it occurred to anyone that software engineers would someday write programs for telephones. It came to Apple by way of NeXT, Steve Jobs’s second startup, which Apple acquired in 1996. When the company drew on NeXT technology to provide the technical underpinnings of the iPhone and iPad, Objective-C was part of the package.

The language doesn’t have a reputation for being a cakewalk to learn or a delight to work in. But Lyft didn’t see it as a particular problem, either. “I would say Objective-C wouldn’t have seen nearly the adoption it saw without iOS, obviously,” says Lambert. “But no one avoided writing Objective-C, no one dreaded writing Objective-C.”

Still, no language with roots dating to the first Reagan administration is going to feel cutting-edge. “You could see the advantages of Swift, just in compactness and the more modern programming paradigm that came into play,” says Pete Morelli, Lyft’s VP of engineering. Moreover, the Lyft app itself was showing its age. The company had whipped up the original version in 2012, when it was known as Zimride and decided to pivot from being a conventional ride-sharing service into something more directly competitive with Uber. As it added features, it slathered them on top of that original foundation.

“Most of the code has been rewritten over the past three years, but some core parts of it were still holding strong,” explains Lambert. “But we would have built a different app if we’d started over.”

“We were a very different company in 2012 when we started this,” adds Sebastian Brannstrom, Lyft’s very first developer. “We basically hacked together Lyft in the course of two weeks, Eduardo [Perez Rico] and me. A lot of the sins of those days are still with us. But that’s how you get started.”

Lyft engineers Sebastian Brannstrom and Martin Conte Mac DonellPhoto: Harry McCracken

Starting Small

If nothing else, moving to Swift would give the company the opportunity to fix every little irritating thing about its code that had built up over the years. But the company still didn’t know enough about Swift to be positive that it was ready for an app as ambitious as Lyft.

So rather than rolling the dice, Lyft did something that wasn’t risky at all. Last September, it assigned a single developer–recent recruit Martin Conte Mac Donell–to start dabbling in Swift. He began putting together a prototype. After a month of working by himself, he had a rough draft working. Basically, it let you request a car.

The experience impressed him. Swift was powerful and easy to learn. “I was actually able to be really, really productive in a short amount of time,” he says.

Lyft’s Swift app

Conte Mac Donell’s confidence made Lyft more confident. “Come January, we definitely had enough to make us confident that this was something we wanted to invest significant resources into,” says Brannstorm. In March, the company began to put more developers on the Swift project. It got even more familiar with the new environs by implementing certain features in the mostly Objective-C version of the app at the same time it was working on the all-Swift revamp. By June, nearly every iOS developer was working in Swift; on average, it took two or three weeks for any given engineer to be up, running, and comfortable.

As Lyft’s engineers dived into Swift, their experience mirrored Conte Mac Donell’s early favorable impressions. “By the time we were working on this Swift project, we were also working in parallel on revamping the entire onboarding flow of the app,” he says. “On the old [version], that was a project that took more than a month, with multiple engineers. And with Swift, that was a project that took a week for one engineer.”

Swift code was also far more compact than Objective-C, which made it easier to understand and manage. Over the years, the original version of Lyft had ballooned to 75,000 lines of code. By the time the company was done recreating it in Swift, they had something that performed the same tasks in less than a third of that.

Flipping The Switch

Swift was so new that Lyft’s engineers were essentially debugging the language itself as well as their app. “Because we were one of the biggest projects using only Swift, we had all the biggest challenges,” says Conte Mac Donell. “We worked side by side with Swift developers in reporting these problems.”

“They were extremely responsive to all the issues we found early on,” adds Morelli. “Having that strong relationship and having that back-and-forth, which can be unusual sometimes with Apple, was really helpful.”

When the company had a Swift app that more or less worked, it began testing it from both a passenger and driver standpoint–the latter of which was possible in part because numerous Lyft employees are also Lyft drivers on the side. “Even with just an employee beta test, we were able to catch driver-side bugs, passenger bugs, the whole ride flow,” says Lambert. “It was a pretty thorough process.”

For all the beta testing Lyft did, it couldn’t be positive how trouble-free its Swift app was until it released it on the app store. And if there were problems, they might affect vast numbers of passengers and drivers all at once, presenting a danger to a business that relies on so many things working correctly in real time.

“One of the challenges of doing something like this is, you don’t really have a viable gradual rollout strategy for iOS,” says Lambert. “Android has a little bit of a leg up there, where you can do a 1%, a 5%, a 10% rollout. With iOS, basically, it’s live or it’s not, which puts a lot of the burden on the engineering team. Everyone who has auto-update turned on on their phone will have it within an hour.”

On July 16, Lyft deployed the Swift version to the App Store. And . . . it worked. Making the day momentous for the company, but utterly uneventful for its passengers and drivers.

In retrospect, one of the most striking things about the project was that it didn’t slow down the development process. Normally, the company pushes out a new version to the App Store on a weekly basis. With the move from Objective-C to Swift, it skipped a weekly cycle–but only one. Which shows that the transition, ambitious though it was, wasn’t a time sink. Instead, Swift’s efficiency compensated for the labor involved in learning a new language and recreating an uncommonly complex app. And it did so right away.

“We saw that as we were porting to this new infrastructure, people were able to do things much faster,” says Morelli. “Even as new features were added, the Swift people were able to catch up.”

As smoothly as the effort went, most of the benefit is yet to come. “Using modern tools opens the doors for everything Apple is already planning—new platforms, new devices,” says Conte Mac Donell. “Everything’s going to revolve around Swift.” As it does, Lyft won’t have to scramble to get with the program. Thanks to its early decision to go all-in with Swift, it’s ready right now.

About the author

Harry McCracken is the technology editor for Fast Company, based in San Francisco. In past lives, he was editor at large for Time magazine, founder and editor of Technologizer, and editor of PC World.

More

Video

More Stories