Learn how to set up a Kitura project from scratch and how to use Swift Package Manager to download Kitura dependencies.
- [Instructor] Before setting up the Kitura project, make sure that you have at least Xcode 9 or higher installed. You can download Xcode and install it from the appstore free of charge. Simply go to the appstore and search for Xcode. Find the latest version, download it, and install it. Xcode 9 uses Swift Package Manager by default which is responsible for downloading and installing and managing dependencies.
We will use Swift Package Manager to install and download the Kitura package into our application. Open up the terminal and create a new folder called 'hello-kitura' on your machine. We are going to create a folder right on the desktop but you are free to create this folder anywhere you like. Name it 'hello-kitura'. Once the folder is created, go ahead and jump inside that folder.
Once you're inside the hello-kitura folder, you will need to use Swift Package Manager to create a default Swift project. This can be done by using 'swift package init --type executable'. This is going to create a default empty Swift project for you. Once you're inside the project, go ahead and open it in your favorite editor. We are going to use Atom in our video.
Now we need to add the dependencies for our IBM package. You can see the dependencies section and also the targets section. Uncomment the package and write the url which points to the Kitura project, which will be https, github.com, IBM-Swift, and Kitura repository which is Kitura.git.
Leave the version number to 1.0.0 because we will be using that particular version. You will also need to add the Kitura dependencies under the target sections. So, in the dependencies keys, simply add Kitura. This is going to make sure that your current Xcode target will have the dependency on the Kitura project. Once you are done, jump back to the terminal and go ahead and execute swift build.
Swift build is going to download all the Kitura's dependencies using the Swift Package Manager. Once the dependencies are downloaded, we should be able to run our application and see what it displays on the console. In order to run the application, simply say .build/debug and the name of the application you are trying to run, which in this case is hello-kitura.
It displays 'Hello, world!' indicating that you have successfully configured a Kitura application. One thing you will notice is that you're not really using Xcode but using Atom or any other text-based editor. iOS developer prefer Xcode and it will be great if we can run the project using Xcode. Don't worry too much about it because Swift Package Manager got you covered. Simply run swift package generate Xcode project and this is going to create an Xcode project for you.
Let's go ahead and open the folder and finally open up the Xcode generated project. You can see that all the dependencies are downloaded in the left bin. In order to run the project, make sure that you select the hello-kitura target and your Mac computer has a destination. When building your Kitura project in Xcode, you may encounter some warnings. Simply ignore those warnings as they are related to the Kitura project transitioning from Swift 3 to Swift 4.
Once everything is set up, simply press the play button. Once you run the project, you will see the same 'Hello, world!' displayed on the output window indicating that you have successfully configured a Kitura project.
- Reviewing the concepts behind server-side Swift programming
- Different server-side Swift frameworks
- Setting up a Kitura project
- Adding HeliumLogger for debugging
- Accessing JSON passed parameters using Kitura.
- Reading URL parameters and URL encoded form parameters
- Configuring the PostgreSQL database
- Fetching, inserting, and deleting records from the database
- Integrating a Kitura API with an iPhone app