This document discusses server-side Swift, including:
- An overview of the history and growth of programming languages from the 1940s to today.
- Features of the Swift programming language like variables, optionals, and closures.
- Tools for server-side Swift development like the Swift Package Manager.
- Benefits of using Swift for server applications like performance, safety, and Apple support.
- Popular web frameworks for Swift including Perfect, Vapor, and Kitura.
- Benchmarking server applications written in Swift.
14. Swift Tour
and more …
• Enumerations
• Inheritance
• Initialization
• Error Handling
• Type Casting
• Generics
• Access Control
• …
• …
15. Swift
Why is Swift a good choice for server-side ?
• Fast
• Modern
• Safe
• Interactive
• Open Source
• Apple
16. Server-side App Trade Off
Why is Swift a good choice for server-side ?AppPerformance
Developer Productivity
C
C++
Obj.C
Java
Perl
JavaScript
Python
Ruby
Lua
Groovy
17. ARC
Automatic Reference Counting (ARC)
Swift manages the memory for you, but unlike many other high level
languages, it doesn’t use a garbage collector to do this.
- No periodically running
- No pause
- The CPU cycles for your own program
19. LLVM
LLVM is actually an umbrella project that includes a variety of compilers and low
level tools
In short, LLVM compiles your code to a platform-neutral Intermediary Representation (IR), which can then be
optimised and converted to the desired architecture. This allows all platform optimisation efforts to be
concentrated in one place
For Swift, Apple added a new layer to this architecture: the Swift Intermediate Language (SIL).
20. SPM
Swift Package Manager
• Part of Swift 3
• Init project
• Generate Xcode Proj
• Resolve dependencies
The Swift Package Manager is a tool for managing the distribution of Swift
code. It’s integrated with the Swift build system to automate the process
of downloading, compiling, and linking dependencies.
Package.swift
21. Swift
• Swift is easier to read
• Swift is easier to maintain
• Swift is safe
• Swift is unified with memory management
• Swift requires less code
Swift vs Objective-C
22. Swift
Swift vs Java
Swift version 3.0-dev (LLVM 491f98861f, Clang 2ff6ce54d0, Swift fd4bd4c965)
swift-DEVELOPMENT-SNAPSHOT-2016-11-29-a-ubuntu16.04
Target: x86_64-unknown-linux-gnu
java version "1.8.0_92"
Java(TM) SE Runtime Environment (build 1.8.0_92-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode)
https://benchmarksgame.alioth.debian.org/u64q/swift.html
29. Install swift to linux
• Install required dependencies
$ sudo apt-get install clang libicu-dev
• Download the latest swift binary release from https://swift.org/download/#releases
• Extract the archive
$ tar xzf swift-<VERSION>-<PLATFORM>.tar.gz
• Add the Swift toolchain to your path
$ export PATH=/path/to/usr/bin:"${PATH}"
• Test with REPL (Read Eval Print Loop)
30. Swift Scripts
#!/usr/bin/env swift
let fruits = ["Banana", "Mango", "Apple", "Orange"]
let sortedFruits = fruits.sorted{$0 < $1}
print(sortedFruits)
chmod +x sort.swift
./sort.swift