Swift

From ArchWiki

According to Wikipedia:

Swift is a general-purpose, multi-paradigm, compiled programming language developed by Apple Inc. and the open-source community. First released in 2014, Swift was developed as a replacement for Apple's earlier programming language Objective-C, as Objective-C had been largely unchanged since the early 1980s and lacked modern language features.

Running Swift-language builds and doing Swift development is possible on Linux.

Installation

Install swift-binAUR for the released version, which is a repackaged Fedora binary, or swift-languageAUR for a native build from source.

Use swift-language-gitAUR for the development version.

For code completion the sourcekit language server protocol, sourcekit-lsp is available, e.g. as plugin to visual studio code, code. See below.

Editing and code completion

Install code, then install sourcekit-lsp from source, nodejs is needed.

$ git clone git@github.com:apple/sourcekit-lsp.git
$ cd Editors/vscode
$ npm run createDevPackage
$ code --install-extension out/sourcekit-lsp-vscode-dev.vsix

Hello world

The Swift package manager allows to create example programs.

$ swift package init --type executable
$ swift run

For a library:

$ swift package init
$ swift build

Read eval print loop, REPL

For details on the swift REPL, see here.

> swift
Welcome to Swift version 5.3 (swift-5.3-RELEASE).
Type :help for assistance.
  1> 1+1
$R0: Int = 2
  2>