Thursday, May 12, 2016

How do you compile and run SWIFT programs on Windows 10?

Presently it is possible to compile and run programs written in SWIFT language on Windows 10. You need to download the program as described in this post.

Programs written in SWIFT has the extension .swift. You can use any text editor and here is a simple program written using Notepad and saved to your hard drive. Note that it has to be in the following directory, C:\SwiftForWindows\Swift

//--Function definition
func sayHello(personName: String) -> String {
        let greeting = "Hello, " + personName + "!"
        return greeting
    }
//Function Call
print(sayHello(personName:"Jay"))
//--

Once you download run the Straightforwards.msi (please see the post at the top) file by double clicking it. There may be warnings from the computer not to run it, but ignore and install it.

This leaves a shortcut on your desktop.

When you click on this shortcut the Swift For Windows window opens as shown.


Swift_02

It is simple to use. Select the file and then hit Compile after choosing your platform. A command-line window opens which you can close if there are no compilation errors.

Swift_03

Close the window and have a look at the Logs. Then hit Run. That's it. Again the comand-line window opens displaying the results of your program.

Swift_04

In summary:
1. Create the Swift program file on a text editor and save it with the extension .swift to a specific directory.
2. Choose the platform you are using
Swift_05

3. Hit Run

That's it.

No comments: