Swift for cross platform client & server side development

Jonathan Guthrie
Server Side Swift and More
3 min readApr 1, 2017

Following on from my previous article on Cross-Platform mobile development with Swift, I managed to get a sneak peak at Beta 2 of SCADE when they asked me to test the nightly builds before the public beta release.

To my delight, as well as dealing with issues reported during Beta 1 (improved installation process, some internal fixes and improvements), they also added a new category of project — a “Server Application Project”.

This means that if I were to create a cross platform mobile app in SCADE, I can also create it’s backend in SCADE as well. That’s a win in my book, one less application to be switching between.

So here’s my experience, as it happened:

Getting set up

Creating the project was surprisingly easy: from the “File” menu, select “New > Scade Project”.

I was presented with the familiar “New Project” dialog. So I gave it a name, and selected “Server Application Project”.

New Project dialog

After clicking “Finish”, SCADE made me a project and poking around it a bit I saw they based it on the Perfect App Template, with what looks like one modification to assist SCADE in piping the console output to the IDE’s console view.

The Perfect App template in SCADE.

One thing I noticed was an additional file called “PerfectDemo.launch”. Opening it up I see there’s mention of a “Working Directory” with the path to the project’s ase directory. This is great because if we want to reference configuration files, log files, SQLite databases, or a webroot directory for static media and Mustache templating, it’s already set.

The acid test: running the project

Selecting the project to execute

The obvious next step was to see if it “just ran”, so after selecting the project in the project selection dropdown beside the run & stop buttons, I ran it.

I suppose I shouldn’t have been surprised, but to be honest I was. At this point I have touched no configuration, no code. But it built, then ran.

In the console view, running on port 8181

The next step to verify was hitting http://localhost:8181/ in a browser. I should see “Hello, world!” — which was exactly what was there.

Next steps

Now this was obviously a very simple test. The next thing I did was to add SQLite support via adding SQLite-StORM support into the Package.swift, customize the template object, add it to the “initializeObjects” function, declare the database location in main.swift, and run it again. This all worked flawlessly: the database file was created in the project directory, the table was created correctly in the database.*

I created a few more routes with some JSON responses and a Mustache templated HTML route. To put it simply, all this is working just as smoothly as if I was doing this in Xcode.

*Note that I haven’t gone to the extent of documenting that process — it’s exactly the same as in this article where I gave an intro to using SQLite and the ORM in https://medium.com/@iamjono/getting-started-with-server-side-swift-1-2-83317c5cfe14

PerfectlySoft is helping out SCADE with running their public beta by hosting the support and discussion channel in the Perfect Slack. If you want to come check it out, join the Slack team via http://www.perfect.ly or if you’re already a member sign in as normal. The channel is #swift-android-ios.

--

--

Jonathan Guthrie
Server Side Swift and More

Developer Evangelist, Musician, and Active Activist... Newmarket ON, Canada