I will keep re-iterating (for the next 6 months at least) that whilst Swift is not the first language from a commercial company to be open-sourced, the enthusiasm and outcomes so far have been astounding.
Swift 2.2 was open sourced just over a month ago on December 3rd 2015 under an Apache 2.0 license. It’s currently hard to find an exact list of projects interpreting and compiling Swift as opposed to written in Swift, but looking at the project’s GitHub repository shows the level of interest, activity and contributions to the project in such a short time frame.
More from this author
Taking a presumptuous name comes ‘Perfect’ from PerfectlySoft Inc, a development agency specializing in tools for Swift developers, releasing the first server-side Swift implementation.
Before we dive into code and usage I asked their CEO, Sean Stephens some questions about their plans and ideas.
Why create the Swift backend project?
We think Swift is a beautiful language but to appeal to an enterprise development ecosystem, it needs a strong server-side framework.
At what state is your Swift backend project?
We have an early release available and hundreds are already using it in their projects. We believe more people will adopt it in the coming months.
Will the project always remain open source or will it become a commercial project?
It will always be open source, but we plan to commercialize it. We believe that there are opportunities for enterprise licensing and configuration utilities to build a strong business, and we are executing a plan to drive this forward.
What do you hope to accomplish?
We are going to take over the server-side development world.
Is anyone using the project with any applications yet? What has performance been like?
We are using the project in production and in all cases it has performed beautifully. It’s still in early stages, so updates are frequent, but the core product is solid. Swift is a wonderful language to work with and Perfect has already greatly reduced our speed to market.
What’s next and what do you need right now?
We have been approached by investors and are currently hiring more engineers to build more and better libraries to improve the product as a whole and build enterprise products for our emerging ecosystem.
Mac OS X
Clone the Swift repository to your machine:
git clone https://github.com/PerfectlySoft/Perfect.git
Inside the project folder open Examples.xcworkspace, this contains a number of example projects you can investigate.
The simplest example to begin with is the ‘Tap Tracker’ application, select the server component in Xcode and click the run button:
And start the matching application:
Find out more about how the ‘Tap Tracker’ application works in Perfect’s documentation. A quick scan will show how well concerns are separated between the two application components. The server-side application handling database transactions with a mustache template file controlling the JSON output passed to the iOS application. This allows the mobile application to just handle getting a location and sending it to the Swift server endpoint. A next step to try would be adding a view that queries the endpoint for taps made and displays them.
This is a great start, but realistically, how many run server-side services on Mac OS X? Swift’s Linux support is the real game changer and Perfect supports this. First make sure you have the Linux Swift compiler installed, then install the dependencies required by PerfectLib:
sudo apt-get install libssl-dev libevent-dev libsqlite3-dev libicu-dev libcurl4-openssl-dev uuid-dev git
Clone and build PerfectLib:
git clone https://github.com/PerfectlySoft/Perfect.git cd Perfect/PerfectLib make sudo make install
Build the Perfect server:
cd ../PerfectServer make
Next we create a shared object for the Perfect server from the project we want to run, so sticking with the tap example:
cd ../Examples/Tap\ Tracker/ make
And copy the resulting output into a new PerfectLibraries folder in the server directory:
cd ../../PerfectServer mkdir PerfectLibraries cp ../Examples/Tap\ Tracker/TapTrackerServer.so ./PerfectLibraries
Finally run the server:
In ViewController.swift of the Tap Tracker application in Xcode, change the
END_POINT_HOST value to the IP address of your Linux server and run it. Everything should be the same as when running the Mac Server, but of course we’re running Swift on two separate machines!
What Else Does Perfect Support?
All we’ve done in these examples is start an existing project, but for experienced Swift developers I hope you’ve already started to see some of the potential of connecting front end and server-side Swift. Here are some other features Perfect offers to sweeten the deal.
Connections to Common Server Components
JSON Object Marshaling
Communication between the server and client side happens in standard JSON. This means there are no new ‘standards’ to learn. This also means that your Swift backend doesn’t have to just feed data to a Swift based front end application. server-side Swift feeding an Android application anyone?
As noted in my interview above, Perfect is new. Development is progressing swiftly (pun intended) but documentation is patchy with exploration and extrapolation needed to get things working. Fortunately the issue queue is not a dead zone where your cries for help will be ignored.
If you are an experienced Swift developer then you should be able to piece information available into something usable and maybe even production ready. If you are new to Swift then things will take you a little longer right now, but rest assured that you are learning one of the most popular programming languages of 2015 that can now take care of your application across the whole stack.
If you like the sound of what Perfect is trying to accomplish, then they have a comprehensive page detailing exactly how you can lend a hand.
What are your thoughts on server-side Swift? Great Promise or bandwagon jumping hype?