Using PerfectLib with macOS apps

Published 20 Aug 2016

While developing a macOS app that needed a lot of file & directory access, as well as a number of curl and command line operations, it struck me that integrating the Perfect framework in my app was a no-brainer idea... this is how.

Some background

In June of this year I joined the team developing Perfect, a server side Swift 3 framework. In doing so I embarked on a rapid learning curve with Swift 3... and while there is a wealth of material out there for Swift 2 implementations of various libraries and tutorials for how to do things in Swift 2, there's not a lot currently for Swift 3. After all, Apple will only be releasing it officially in September 2016.

As a result, what you read here is possibly going to change. As at the time of writing the latest build is against the Swift 3 snapshot 08-18. I will attempt to keep this entry up to date up until Apple releases Swift 3.0 in September.

Why would I include a server side framework in a macOS app?

Yes, I know, Foundation includes the filemanager and it's possible to use that for file system operations.

Yes, I know, you can also create routines in Swift that execute command line directives.

But, with the PerfectLib embedded you don't need to recreate the wheel. Reading, writing files is more efficient in your code. Parsing JSON is a snap. Cloning a repo from GitHub is a piece of cake.

Steps

0. Install Xcode 8

If you don't already have Xcode 8 installed... get it, install it. This will *not* work with Xcode 7.x

1. Clone the Perfect repo, build and generate an Xcode project

In the terminal, navigate to a place in your hard drive where you'd like to keep the library, execute: