Server-side Swift
Since Swift is a language that is elegant and expressive while being performant, it was about time that it would be ported to run on a server-side platform. Building command-line tools with Swift become popular on the macOS platform soon after Apple made it easy to use Swift for general purpose programming outside of iOS app development with the use of the Hash Bang, #!, syntax specified on top of the Swift file just like in a scripting language such as Perl, Ruby, or Python. This made it very easy for anyone to write and run Swift code without having to compile it. The same technique works on Linux platform; so, let's see how it works:
- Creating a Swift file called hello.swift
- Adding the following code to the file:
#!/usr/bin/swift
print(“Hello World from Swift!”)
- Making the file an executable by changing the permission on the file using chmod:
$ chmod +x hello.swift
- Running the Swift code by typing the filename in the Terminal:
$ ./hello.swift
You should see Hello World from Swift! printed on the command line. This shows you how easy it is to create an executable in Swift without even having to compile it ahead of time; you can quickly test Swift code from the command line.