Run & Debug a Swift Kitura Web Application Locally from Xcode

kitura_swift_bluemix_xcode
Here are my notes on getting a Kitura application running from Xcode locally on my mac.

Create the project
1. Sign up for a Bluemix account. It’s free to start, and there is a free tier to continue using the service.
2. Install the IBM Cloud Tools for Swift GUI App, and sign in with the account you just created.
3. Create a Kitura project using the IBM Cloud Tools for Swift app. It’s a pretty intuitive process but you can find it spelled out here.
4. The Kitura project creation process will create a number of files in a directory on your local machine (which you would have picked during the previous step). Navigate to this directory (there should be a file Package.swift in there) using the terminal.

Add the proper toolchain
5. Find the appropriate toolchain version. The readme file in the Kitura project should specify which toolchain to use. At the time of this writing DEVELOPMENT-SNAPSHOT-2016-05-03-a was specified.
6. Download the toolchain specified from above from the swift.org snapshot repository.  You can identify the proper toolchain by matching the date in the filename of the specified snapshot from step 5.
7. Install the toolchain by double clicking on it. From the terminal, temporarily add it to your path like so:
export PATH=/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin:$PATH

Prepare Xcode
8. Create the Xcode project. From the terminal run swift build -X
9. From the terminal run make which will create and populate a .build folder. You’ll need this later (in step 11) when you link to two of the libraries from Xcode that make builds and places in that folder.
10. Open the project in Xcode. From the menu bar select Xcode->Toolchains->(the toolchain you installed earlier). Xcode will restart.
11. Add $SRCROOT/.build/debug to the Library Search Paths for the Kitura and KituraNet targets.
12. Select the executable build scheme and run it. The Xcode console will specify the url and port the server is accessible at. Paste this into a browser to poke it.
13. Toss in a breakpoint and start stepping through code.

You’re now debugging a web application written in Swift. Heck yeah!

 

references:
https://github.com/IBM-Swift/Kitura-Sample/issues/14
https://github.com/IBM-Swift/Kitura/wiki/Building-your-Kitura-application-on-XCode/26ea27c204714ffa73e972b9c9046e749bb8fc1f
https://developer.ibm.com/swift/2016/06/13/ibm-cloud-tools-for-swift/

Leave a Reply

Your email address will not be published. Required fields are marked *