官术网_书友最值得收藏!

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 itThe same technique works on Linux platform; so, let's see how it works:

  1. Creating a Swift file called hello.swift
  2. Adding the following code to the file:
#!/usr/bin/swift
print(“Hello World from Swift!”)
  1. Making the file an executable by changing the permission on the file using chmod:
$ chmod +x hello.swift
  1. 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.

主站蜘蛛池模板: 彩票| 南安市| 昔阳县| 夏津县| 泰州市| 日土县| 简阳市| 十堰市| 滕州市| 拜城县| 清丰县| 昭觉县| 福海县| 田东县| 保亭| 桑植县| 永昌县| 新河县| 昭觉县| 东明县| 塔城市| 满洲里市| 锡林浩特市| 华坪县| 荥阳市| 牙克石市| 科技| 漠河县| 乌鲁木齐县| 霍州市| 洛扎县| 车致| 台州市| 建昌县| 沂水县| 盱眙县| 康定县| 兴义市| 大冶市| 子长县| 临江市|