WWDC 20
What's new in Swift
Improvements to binary size, especially in SwiftUI apps
Smaller memory usage overhead from things like internal caches of the Swift runtime (use iOS 14 deployment target for best effect)
Apple can now use Swift in very low level frameworks, where previously only C was available
Much better compiler diagnostics (warnings and errors)
New diagnostics subsystem that helps identifying code issues much more precisely
More actionable errors with guidance how to fix them
Improved code completion
Code completion better understands features such as ternary operator or keypaths
Drastically improved performance, up to 15x faster
Improved code indentation in things like: chained calls, call arguments, multi-line control flow statements
Better error messages for runtime failures like arithmetic overflow
Debugging improvements: improved module importing which should lead to less issues while evaluating variables in lldb
Cross-platform support:
Improved support for various distributions of Linux
Coming soon: initial support for Windows
Swift AWS Lambda runtime
New language features:
Multiple trailing closures
(API design tip: design names for methods with closure arguments so that the call site still makes sense if a trailing closure w/o an argument label is used)
Keypaths can be used as functions, so you can pass them to APIs that expect a function, like xx.map(\.field)
(this is from Xcode 11.4)
@main
β marks the entry point to the program
As a library author, you can declare a static function main()
in a class or type
Users can then use an instance of that type with the tag @main
, and compiler implicitly creates a main.swift
file that calls that function
class Foo { public static func main() { β¦ } }
import FooKit @main class Hello: Foo { β¦ }
Replaces the old @UIApplicationDelegate
which could only be used in the specific context of UIApplicationDelegate
Increased availability of implicit self
in closures:
- you can skip
self.
if you capture[self]
in the closure arguments - you can skip
self.
ifself
is a struct or enum (like in SwiftUI)
Multi-clause catch statements in do-catch
Automatic comparable conformance for (some) enum types
Enums can fulfill protocol requirements requiring static properties (plain case) and static functions (case with arguments)
View builders improvements:
- support for more kinds of statements, e.g. switch and if-let
- adding a view builder annotation to body declaration if it has more than one children is not necessary anymore
Float16
β a float type that uses 2 bytes (half of standard float)
Apple Archive β new archive file format, .aar
extension
Fast, uses multithreading
Includes a command-line tool and Finder integration
Swift API β AppleArchive framework
Swift System β Swift interfaces to system calls and other low level APIs
OSLog:
Improved performance
Support for string interpolations and formatting options:
logger.log("\(offerID, align: .left(columns: 10), privacy: .public)") logger.log("\(seconds, format: .fixed(precision: 2)) seconds")
Packages available on GitHub:
Swift Numerics
Swift Argument Parser
Swift Standard Library Preview