2020 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 ↗Code shown on screen · 6 snippets
Swift on AWS Lambda
import AWSLambdaRuntime
Lambda.run { (_, event: String, callback) in
callback(.success("Hello, \(event)"))
} @main
// Type-based program entry points
import ArgumentParser
@main
struct Hello: ParsableCommand {
(help: "The name to greet.")
var name: String
func run() {
print("Hello, \(name)!")
}
} Synthesized comparable conformance for enums
// 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
// 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
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 ArgumentParser
import ArgumentParser
@main
struct Hello: ParsableCommand {
(name: .shortAndLong, help: "The number of times to say hello.")
var count: Int = 1
(help: "The name to greet.")
var name: String
func run() {
for _ in 1...count {
print("Hello, \(name)!")
}
}
} Resources
Related sessions
-
28 min -
8 min -
17 min -
16 min -
15 min