In the post Running Swift on Ubuntu Server (on VirtualBox) we installed swift on an Ubuntu Server 15.10 installed in VirtualBox virtual machine and then we have compiled our first swift program, naturally it was hello world.

This time we are going to use the Package Manager provided by Apple to create a real project.

Let’s start our virtual machine and login in it.

When the shell is ready issue the following command to create the directory structure for the HelloWorld project:

At this point we have to create the Package.swift file for our project. You can use your favourite editor, the file shall containing the following code:

swift_ubuntu_virtualbox
Now move into the sources directory

and create the main.swift file containing the code

Save the file and go back to the project root directory

It is time to build the HelloWorld executable

now your HelloWorld program should be built. Try running it, note that the “swift build” command creates a complete directry structure inside the root of your project. The directory is invisible, its name is .build. So issue the following command to execute your progam:

Let’s add a new class to the project, go to the sources directory

and create the classA.swift file with the following code:

The above class have two initializers (which initiliaze the two properties) and a function which prints out the two properties.

Now modify again the main.swift file, the new content will look like the following:

Move back to the project root

and build the executable

Run your application

Really this is not a very complex application, but, at this point we are using the right tool to handle more complex projects.

Gg1