Dunfey · Hotel WWDC as data, est. 1983
Front desk everything
Years
Topics

2020 Swift

WWDC20 · 32 min · Swift

What’s new in Swift

Join us for an update on Swift. Discover the latest advancements in runtime performance, along with improvements to the developer experience that make your code faster to read, edit, and debug. Find out how to take advantage of new language features like multiple trailing closures. Learn about new libraries available in the SDK, and explore the growing number of APIs available as Swift Packages.

Watch at developer.apple.com ↗

Transcript all transcripts

Code shown on screen · 6 snippets

Swift on AWS Lambda swift · at 13:32 ↗
import AWSLambdaRuntime

Lambda.run { (_, event: String, callback) in
    callback(.success("Hello, \(event)"))
}
@main swift · at 21:08 ↗
// Type-based program entry points

import ArgumentParser

@main
struct Hello: ParsableCommand {
    @Argument(help: "The name to greet.")
    var name: String

    func run() {
        print("Hello, \(name)!")
    }
}
Synthesized comparable conformance for enums swift · at 23:50 ↗
// Synthesized comparable conformance for enums

enum MessageStatus: Hashable, Comparable {
    case draft
    case saved
    case failedToSend
    case sent
    case delivered
    case read

    var wasSent: Bool {
        self >= .sent
    }
}
Compress and archive a source directory using Apple Archive swift · at 27:19 ↗
// Apple Archive

import AppleArchive

try ArchiveByteStream.withFileStream(
    path: "/tmp/VacationPhotos.aar",
    mode: .writeOnly,
    options: [.create, .truncate],
    permissions: [.ownerReadWrite, .groupRead, .otherRead]
) { file in
    // Receives raw bytes and writes compressed bytes to `file`
    try ArchiveByteStream.withCompressionStream(using: .lzfse, writingTo: file) { compressor in
        // Receives archive entries, and writes bytes to `compressor`
        try ArchiveStream.withEncodeStream(writingTo: compressor) { encoder in
            // Writes all entries from `src` to `encoder`
            try encoder.writeDirectoryContents(archiveFrom: source, keySet: fieldKeySet)
        }
    }
}
OSLog support for String interpolations and formatting options swift · at 28:34 ↗
logger.log("\(offerID, align: .left(columns: 10), privacy: .public)")
// Logs "E1Z3F    "

logger.log("\(seconds, format: .fixed(precision: 2)) seconds")
// Logs "1.30 seconds"
ArgumentParser Swift Package swift · at 30:05 ↗
// Swift ArgumentParser

import ArgumentParser

@main
struct Hello: ParsableCommand {
    @Option(name: .shortAndLong, help: "The number of times to say hello.")
    var count: Int = 1

    @Argument(help: "The name to greet.")
    var name: String

    func run() {
        for _ in 1...count {
            print("Hello, \(name)!")
        }
    }
}

Resources