Swift, often referred to as “Objective-C, without the C,” is an open-source programming language developed and maintained by Apple. Swift is a general-purpose programming language built using a modern approach to safety, performance, and software design patterns. The Swift project aims to create the best available language for uses ranging from systems programming to mobile and desktop apps, scaling up to cloud services.
In the following tutorial, you will learn how to install Swift on Ubuntu 20.04 and 21.04.
To download Swift, visit the official download page that has the latest version listed. In time, these will change, but the tutorial will use an example of how to download Swift version build 5.4.2 using the wget command as follows:
Once the path is exported, you can activate the .bashrc file with the following command:
To round off the installation, verify the version and build:
You should get a similar output:
Connect to Swift REPL on Ubuntu 20.04
To connect to the Swift REPLL (Read Eval Print Loop) can be achieved using the following command:
You can write and valid Swift statements in this terminal and see them evaluated, and you can even use standard C Libraries by importing the GNU C Libary.
Below are some basic examples of Swift in action:
To exit the Swift terminal, use the following command:
Comments and Conclusion
In the tutorial, you have learned how to install Swift programming language by learning how to download and import the PGP key, extract the bash and path required for it, and basic commands to get a feel for the Swift terminal.
Overall, Swift is fast, safe, modern, and enables a level of interactivity in development. It contains several features such as closures, generics, and type inference, making it easier to use, simplifying common patterns used in Objective-C. Swift combines features of both C and Objective-C without having direct built-in C compatibility and all the constraints that come along with it.