Since you have just made your first program on Swift in Linux, I advise you to follow other tutorials and documentations on official Swift website.This was as big a news for Linux users as Microsoft open sourcing.net.If you are itching to know about using Swift in Linux, then I have a basic tutorial for you.
This tutorial will help you in getting started with Swift in Linux. Tutorial includes installation of Swift in Linux and help set up the environment for writing the first Hello World program in Swift. Things to note here is that at the time of writing this article, Swift for Linux is still under heavy development. I am using Ubuntu 15.10 for this tutorial, but you can use the same steps for Ubuntu 14.04 as well. Swift Programming On Windows Download The FilesInstalling Swift in Ubuntu Linux Step 1: Download the files Apple has provided snapshots for Ubuntu. Download Swift for Ubuntu Alternatively, you can use the commands below to download Swift for respective Ubuntu versions. I strongly advise to use the link above because the files are being regularly updated and the links in the command below might become outdated soon. For Ubuntu 14.04, use the command below: wget For Ubuntu 15.04, use this command below: wget Step 2: Extract the files In the terminal, switch to Downloads directory using the command below: cd Downloads And in here, extract the downloaded file: tar -xvzf swift-2.2-SNAPSHOT This will create a directory named swift-2.2-SNAPSHOT-2015-12-10-a-ubuntu15.10 (or something similar). Step 3: Set up environment variables Once you have extracted the files, time to set up the path to binaries so that you could execute the programs. There is a usrbin directory in your extracted directory. For this you would need the absolute path to the extracted directory. Considering that you have followed the exact steps I mentioned, your extracted files would be in homeDownloads location. ![]() So, when you have the path to bin directory, add them to the PATH variable like this. Do change the value of pathtoswiftusrbin in the command below. Step 4: Install dependencies Youll have to install a few dependencies to make Swift work in Linux. ![]() ![]() Thats a different procedure. Swift Programming On Windows How To Make ABuilding a sample Swift project This part will show you how to make a Swift project that prints Hello World. After all, most of the programming language tutorials start with Hello World, isnt it In the directory of your choice, create a Hello directory and switch to it: mkdir Hello cd Hello We have just created a Swift package named Hello. But it is not complete yet as there each package must have Package.swift file. Create this file using this command: touch Package.swift You need to have a Sources directory with main.swift file in it. Sources touch Sourcesmain.swift Now, edit this main.swift file. You can use a graphical text editor or do it in command line. All you need to put the following line in the file: print(Hello, world) Now use the below command to compile it: swift build This will give you the executable program in.builddebugHello. Run the program and you will see Hello, world printed in the output:.builddebugHello Screenshot to give you an idea: Next step Well, as I had said in the beginning, this tutorial is not going to teach you Swift programming. This is more of getting started with Swift in Linux with configuration and settings. Unlike Xcode, you wont get to use Playground to easily create iOS apps. You can use Atom for programming and debugging Swift but its not the same experience as Xcode.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |