Share live code in your browser. Start Free with 20 monthly hours.


Alvaro Pereyra - CEO

Swift (which we announced support last week) is the kind of language you weren't expecting, but when it arrives, it makes you rethink a thing or two about how you were approaching development.

 Before working on CodePicnic, we built one or two iOS apps as soon as Apple announced it and fell totally in love with its neat balance between bringing modern language features but also the stability and support of existing paradigms. It was "sweet enough". 

And yet, there was an issue that took us from using it more. It was mobile only, and thus limited on that sense to building mobile apps. And so we played a bit, and learned some more and moved onto other things.

Sooner than later, though, changes in the horizon started to came around. Apple decided to open source it, letting legions of developers that previously hadn't had a chance to use it, to start building and expanding the already big ecosystem.

And then, Perfect was released and once again, things changed more, in the most perfect sense.

Perfect is a server-side framework built with Swift. It won't only let you build a complete full-stack application in the same language you were building your mobile app, but also reuse application logic (objects, utility classes and such) between all ends, bringing up both worlds together.

And though it's a new project by itself, it's also pretty complete, letting developers tackle the usual tasks from running the web server to creating your own API endpoints, ready to be consumed by client apps. And supporting your existing Swift libraries. More cool still? You could also build it as another target to your Xcode project, and build it alongside your app. Talk about a game changer.

Better still, you can start using it right now, here at CodePicnic. Along side our Swift support (and have you tried our Swift 3 Preview consoles already? That's gonna be something to look forward) now you can also start trying what Perfect brings to the table directly in your browser.

As a small appetizer, I went ahead and cloned one of their examples which you can use below. It's fully working and you can launch the server by using the perfectserverhttp --libpath . binary (or go ahead and press the Play button, we'll do the rest). When you're done, head to the browser tab and check out the result.

You could also try browsing /foo/bar/baz or /user/1. Each of them will get a different result processed by Perfect. 

How is this working? Of interest, let's check the PerfectHandlers file found at /app/URL Routing/PerfectHandlers.swift. This will act as the server router, mapping what will happen for each endpoint.

In this case, you'll see how regular "/" calls will call the indexHandler function (which, itself, writes a response back to the client). 

GET and POST requests are handled right now, but extending it to support the regular RESTful verbs is as easy as adding them to that file (and obviously, eventually splitting it into a more complete app). 

You can find some useful resources to keep on learning (and figuring out how to add it to Xcode, for instance) at We specially recommend the Perfect: Server Side Swift - Setup, Request Handling, and MySQL Connection

Overall, we think Perfect is a great new tool to keep around for those moments where you don't feel like switching to another workflow. As usual, we'll keep providing out-of-the-box support to it and keeping an eye on how everything evolves in the future. 

As it happens, it's time to start playing and learning. Happy coding to you all!

comments powered by Disqus

Wanna learn more about what we do?

Check our Features, our Documentation or drop us a line