Why You Should Learn Server-Side Swift

If you’ve been watching the server-side Swift changes this year, you may have noticed the building momentum. The Vapor community reinforced their commitment to server-side Swift by pushing significant updates in Vapor version 4.  That was followed by a new server-side Swift platform — the  Swift AWS Lambda Runtime, complete with a WWDC video. Apple also dropped Vapor’s name during a State of the Union demo. Finally, the Swift Server work group has been expanding, so we should expect to see more server-side Swift features trickling out in the near future.

I hope some of the recent positive developments encourages you to consider why Swift on the server may be a good choice for your next server project. But I’d really like to encourage iOS developers to consider writing Swift server apps, even as experiments, to make better iOS apps. There is a synergy between iOS development and Swift server development that compliment one another and justify the investment.

Modularizing your App

To leverage the benefits of Swift server development, you will likely want to share some existing iOS app code with the server. The server-side solutions are built around the Swift Package Manager. If you are not already using packages to modularize your iOS app, you will need to spend some time moving code into a package. This requires separating the iOS-specific parts (ex: UIKit) from the things you want to reuse on the server. The scope of this effort depends on how intertwined the project code is. But once you move even a portion of your app code to a package, you will likely be thrilled to watch in run on a server. Your code is now more modular, opening up opportunities to extend to even other iOS apps.

Become more proficient with Swift

To learn a new development skill, we often need to experiment with technologies that add little value to our primary skill sets. Take for example my desire to expand to server-side development several years ago. My day job consisted of iOS development but I wanted to learn about the web. So I ventured into the world of Node.js and created a few simple web apps for personal use. While I don’t regret doing that, the results could have been better. These web apps got very little of my attention as I didn’t have a good reason to maintain my Node.js skills and I’d cringe at the idea of jumping back into unfamiliar code. 

I can contrast that experience with the time I took recently to convert those apps to Swift Vapor apps. In this case I’m working with Swift — a language I’m familiar with. If I return to that project in a year, I’ll at least be comfortable with the language. Additionally, each time I work with Swift on the server, there is a chance I will learn something new about Swift. That value will translate into better apps on both sides and help justify the time spent.

Time To Learn Something Really New

As I mentioned, it is compelling to learn a new skill that strengthens your existing skills — like cross-platform Swift. But I think we all crave an unfamiliar challenge too. Apple offers a stream of new APIs to keep us busy. But the environment for server-side Swift is a different animal. Working with technologies like Docker, Linux, AWS and Heroku is unlike anything you will see in the Xcode editor. That shift in paradigms may widen your perspective on development possibilities for your company/app and build some confidence to take on even bolder solutions.

How to Get Started

I suggest starting with small experiments to get comfortable in this space. Maybe write a Hello World app with Vapor 4 and contrast that experience with running Swift code on a server with an AWS Lambda deployment. Once you are comfortable with the basics, consider migrating parts of your app to a dedicated Swift Package that can be used by Vapor or AWS. I think you won’t regret the time spent here and at a minimum will learn some new Swift skills, have a more modular app and will have some fun taking on a new challenge.

Vapor Resources

Vapor 4 Getting Started

Vapor 4 Tutorial – Tim Condon

AWS Lambdas Resources

AWS Swift Lambda Announcement – Tom Doron

WWDC Tutorial – Tom Doron

Getting Started With Swift on AWS Lambda – Fabian Fett

HTTP Endpoint With AWS Lambdas – Fabian Fett

Developer Experience Using AWS Swift Lambdas – Adam Fowler