Learning a new technology is a time consuming process. It was for Android with Java. And it was again for iOS with Swift. I’m now faced with the challenge of needing to provide a server backend for both Android and iOS apps. However, I would like to avoid the large time investment of learning a new language if possible. From what I have heard, the server code could be written in either Java or Swift, but Swift seems to be to be a much cleaner language so that is why I have chosen to go this route.
I want to make a proof-of-concept example where a server running Swift is able to communicate with an Android and iOS app. The apps send a request and receive a response.
The content below is my introduction into Server Side Swift.
A basic example involves three things:
- A Linux server running Swift
- An Android app
- An iOS app
The focus of this answer is on the Swift server.
Linux server running Swift
These directions are based on unit one of the free Udacity course titled Server-Side Swift. I recommend taking the whole thing. There have been updates since then, but it explains things slowly and clearly.
1. Log in over ssh to your Linux server
In this example we will use a VPS with a static IP. If you don’t have one you can get one from quite a few places. LowEndBox has inexpensive options. I’m using Ubuntu Linux for this example. You should receive an ip address for the server along with a root password.
Depending on what your VPS has installed, you may want/need to install the following dependencies.
sudo apt-get install nano(text editor, more intuitive than
sudo apt-get install git
This will help you download Swift server and manage different version environments. The installation directions are pretty clear. Choose the Git option.