Swift

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

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.

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>
gollark: And an annoying to remember one.
gollark: Ah, so the "true name" is CLEARLY just a UUID.
gollark: Frankly, Lyricly, you are.
gollark: I mean, computers are quite dense metal/silicon/whatever PCBs are made of.
gollark: Plausibly, if we remove all the air from the computers.
This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.