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.
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:
git clone https://github.com/PerfectlySoft/PerfectLib.git cd PerfectLib swift build swift package generate-xcodeproj
This checks out the latest PerfectLib, builds it, and generates an Xcode 8 project.
2. Create an Xcode Workspace including your macOS project
If you haven't already created an Xcode Workspace for your project, do so. Your project should be inside it.
3. Add Perfect to your Workspace
Drag the Xcode project we created in step 1 into the Workspace. You'll see it beside your macOS project.
4. Build PerfectLib in Xcode
In step 1 we build PerfectLib with the terminal. While that verifies that all is well, it doesn't provide Xcode with what it needs.
Select the PerfectLib scheme in Xcode, and press cmd-B to build it.
5. Include PerfectLib as a "Linked Framework"
6. Import PerfectLib in your code and use it
In your code, now you can use PerfectLib:
And that's all there is to it.
I am hoping that once Xcode 8 gains proper support for the Swift Package Manager this will all become much easier, but for now even the "hard" way should be achievable for most people.