IceCubesApp/Packages/RSS/Tests/RSSTests/HTMLToolsTests/swift-org--atom.xml

2729 lines
330 KiB
XML
Raw Normal View History

2024-03-07 02:16:40 +00:00
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title type="text" xml:lang="en">Swift.org</title>
<link type="application/atom+xml" href="https://swift.org/atom.xml" rel="self"/>
<link type="text/html" href="" rel="alternate"/>
<updated>2024-03-02T07:00:07-04:00</updated>
<id>tag:swift.org,2015-12-03:Swift</id>
<entry>
<title>Swift joins Google Summer of Code 2024</title>
<author>
<name>Swift.org</name>
</author>
<link href="https://swift.org/blog/swift-google-summer-of-code-2024/"/>
<updated>2024-02-23T06:00:00-04:00</updated>
<id>https://swift.org/blog/swift-google-summer-of-code-2024/</id>
<content type="html">&lt;p&gt;Were happy to announce that Swift will once again be joining &lt;a href=&quot;https://summerofcode.withgoogle.com&quot;&gt;Google Summer of Code 2024&lt;/a&gt;!&lt;/p&gt;
&lt;p&gt;Summer of Code is an annual program, organized by Google, which provides hands-on experience for newcomers contributing
to open source projects. Participants usually are students, but do not have to be.&lt;/p&gt;
&lt;p&gt;Swift has been participating in Summer of Code since 2018, and every year weve had successful projects,
helping the Swift project among various aspects including the compiler, runtime, and general package and tooling ecosystem.
If youre curious, here are the two most recent project summaries for &lt;a href=&quot;https://www.swift.org/blog/swift-summer-of-code-2022-summary/&quot;&gt;2022&lt;/a&gt; and &lt;a href=&quot;https://www.swift.org/blog/summer-of-code-2023-summary/&quot;&gt;2023&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Many GSoC participants become part of the Swift community and keep contributing even as the program ends.
This is the most exciting part for us: helping you become a part of the Swift community!&lt;/p&gt;
&lt;p&gt;If you are &lt;a href=&quot;https://summerofcode.withgoogle.com/get-started&quot;&gt;eligible&lt;/a&gt;, and would like to contribute to Swift during
this years GSoC, these are the steps to take:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Check out the existing &lt;a href=&quot;https://www.swift.org/gsoc2024/&quot;&gt;project ideas page&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;If a project excites you, &lt;a href=&quot;https://forums.swift.org/c/development/gsoc/98&quot;&gt;proceed to the GSoC category on the Swift forums&lt;/a&gt; to discuss the project.&lt;/li&gt;
&lt;li&gt;Once you are confident in your understanding of the project and how to approach it, &lt;a href=&quot;https://google.github.io/gsocguides/student/writing-a-proposal&quot;&gt;write an official proposal&lt;/a&gt; and submit it to the &lt;a href=&quot;https://summerofcode.withgoogle.com&quot;&gt;GSoC website&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;You can also come up with your own project ideas. To do so, youll need to start a discussion thread &lt;a href=&quot;https://forums.swift.org/c/development/gsoc/98&quot;&gt;on the forums&lt;/a&gt; and pitch the idea similar to how the existing
ideas are listed on the ideas page. Proposing new ideas is exciting, but more difficult as youll have to ensure the project gets a mentor willing to take it on.&lt;/p&gt;
&lt;p&gt;The forums are also a great resource of past GSoC discussions and projects. You can also read the &lt;a href=&quot;https://google.github.io/gsocguides/student/index&quot;&gt;GSoC Contributor Guide&lt;/a&gt; to get a good grasp of what participating in the program entails.&lt;/p&gt;
&lt;p&gt;Official proposal applications need to be sent through the Summer of Code website.
Applications start on March 18, 2024, and end on April 2, 2024 at 18:00 UTC.&lt;/p&gt;
&lt;p&gt;We look forward to working with you all again this year!&lt;/p&gt;
</content>
</entry>
<entry>
<title>On-device ML research with MLX and Swift</title>
<author>
<name>Swift.org</name>
</author>
<link href="https://swift.org/blog/mlx-swift/"/>
<updated>2024-02-20T06:00:00-04:00</updated>
<id>https://swift.org/blog/mlx-swift/</id>
<content type="html">&lt;p&gt;The Swift programming language has a lot of potential to be used for machine learning research because it combines the ease of use and high-level syntax of a language like Python with the speed of a compiled language like C++.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/ml-explore/mlx&quot;&gt;MLX&lt;/a&gt; is an array framework for machine learning research on Apple silicon. MLX is intended for research and not for production deployment of models in apps.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/ml-explore/mlx-swift/&quot;&gt;MLX Swift&lt;/a&gt; expands MLX to the Swift language, making experimentation on Apple silicon easier for ML researchers.&lt;/p&gt;
&lt;p&gt;As part of this release we are including:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A comprehensive Swift API for MLX core&lt;/li&gt;
&lt;li&gt;Higher level neural network and optimizers packages&lt;/li&gt;
&lt;li&gt;An example of text generation with Mistral 7B&lt;/li&gt;
&lt;li&gt;An example of MNIST training&lt;/li&gt;
&lt;li&gt;A C API to MLX which acts as the bridge between Swift and the C++ core&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We are releasing all of the above under a permissive &lt;a href=&quot;https://github.com/ml-explore/mlx-swift/blob/main/LICENSE&quot;&gt;MIT license&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This is a big step to enable ML researchers to experiment using Swift.&lt;/p&gt;
&lt;h3 id=&quot;motivation&quot;&gt;Motivation&lt;/h3&gt;
&lt;p&gt;MLX has several important features for machine learning research that few if any existing Swift libraries support. These include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Native support for hardware acceleration. MLX can run compute intensive operations on the CPU or GPU.&lt;/li&gt;
&lt;li&gt;Automatic differentiation for training neural networks and the gradient-based machine learning models&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For more information on MLX see the &lt;a href=&quot;https://ml-explore.github.io/mlx&quot;&gt;documentation&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The Swift programming language is fast, easy-to-use, and works well on Apple silicon. With MLX Swift, you now have a researcher-friendly machine learning framework with the ability to easily experiment on different platforms and devices.&lt;/p&gt;
&lt;h3 id=&quot;a-quick-tour&quot;&gt;A Quick Tour&lt;/h3&gt;
&lt;p&gt;Getting &lt;a href=&quot;https://ml-explore.github.io/mlx-swift&quot;&gt;set up&lt;/a&gt; with MLX Swift is quick and easy with Xcode or SwiftPM.&lt;/p&gt;
&lt;p&gt;In MLX Swift, building and performing operations with N-dimensional arrays is simple. In the following example, all of the operations will be run on the default device, which is the GPU unless otherwise specified.&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;MLX&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;MLXRandom&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;MLXRandom&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;normal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// array([-0.125875, 0.264235], dtype=float32)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;MLXArray&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;..&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// array([[0, 1],&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// [2, 3],&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// [4, 5]], dtype=int32)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// last element of 0th row&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// array(1, dtype=int32)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// slice of the first two rows &lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;..&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// array([[0, 1],&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// [2, 3]], dtype=int32)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// add with broadcast&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// array([[-0.510713, 1.04633],&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// [1.48929, 3.04633],&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// [3.48929, 5.04633]], dtype=float32)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;You can also use function transformations in MLX Swift. Function transformations in MLX are useful for training models with automatic differentiation as well as optimizing compute graphs for speed or memory use. Below is an example which computes the gradient of a function.&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;MLXArray&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;MLXArray&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;square&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;gradFn&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;grad&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;MLXArray&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;dfdx&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;gradFn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// prints 2 * 1.5 = 3&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dfdx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;The documentation contains a few more complete &lt;a href=&quot;https://ml-explore.github.io/mlx-swift/MLX/documentation/mlx/examples&quot;&gt;examples&lt;/a&gt; to help you get started with MLX Swift:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Text generation with an LLM: A complete LLM text generation example with Mistral 7B. The example will generate text using any Mistral or Llama-style model including pre-quantized MLX models, many of which are available on &lt;a href=&quot;https://huggingface.co/models?library=mlx&amp;amp;sort=trending&quot;&gt;Hugging Face&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Training an MLP on MNIST: The example trains a simple multi-layer perceptron to classify MNIST digits using the MLX Swift neural network and optimizers packages.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;further-resources&quot;&gt;Further Resources&lt;/h3&gt;
&lt;p&gt;Here are a few more resources to get started with MLX Swift:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://ml-explore.github.io/mlx-swift&quot;&gt;Swift documentation and examples&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/ml-explore/mlx-swift&quot;&gt;GitHub repository&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;We encourage you to file an &lt;a href=&quot;https://github.com/ml-explore/mlx-swift/issues&quot;&gt;issue&lt;/a&gt; if you encounter any problems or have suggestions for improvements.&lt;/li&gt;
&lt;li&gt;We welcome contributions. If you are interested in contributing to MLX Swift, check out our &lt;a href=&quot;https://github.com/ml-explore/mlx-swift/blob/main/CONTRIBUTING.md&quot;&gt;contribution guidelines&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
</content>
</entry>
<entry>
<title>Swift Summer of Code 2023 Summary</title>
<author>
<name>Swift.org</name>
</author>
<link href="https://swift.org/blog/summer-of-code-2023-summary/"/>
<updated>2024-02-13T06:00:00-04:00</updated>
<id>https://swift.org/blog/summer-of-code-2023-summary/</id>
<content type="html">&lt;p&gt;The Swift project regularly participates in &lt;a href=&quot;https://summerofcode.withgoogle.com&quot;&gt;Google Summer of Code&lt;/a&gt; in order to help people new to the open source ecosystem dip their toes in contributing to Swift and its growing ecosystem.&lt;/p&gt;
&lt;p&gt;During the 2023 edition of the program, we ran three projects, all of which completed their assigned projects successfully.&lt;/p&gt;
&lt;p&gt;The projects in this edition were:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Swift Memcache Library&lt;/li&gt;
&lt;li&gt;Incremental Parsing in SwiftParser&lt;/li&gt;
&lt;li&gt;Key Path Inference and Diagnostic Improvements&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Wed like to extend our sincere thanks to the participants and mentors who poured their time and passion into these projects, and use this post to highlight their work to the wider community. Below, each project is described in a small summary.&lt;/p&gt;
&lt;p&gt;Lets take a look at each project, in the words of the mentees and mentors themselves:&lt;/p&gt;
&lt;h3 id=&quot;swift-memcache&quot;&gt;Swift Memcache&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Mentee: &lt;a href=&quot;https://github.com/dkz2&quot;&gt;Delkhaz Ibrahimi&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Mentor: &lt;a href=&quot;https://github.com/FranzBusch&quot;&gt;Franz Busch&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The goal of the project was to develop a native &lt;a href=&quot;https://memcached.org&quot;&gt;Memcached&lt;/a&gt; connection abstraction for the Swift on Server ecosystem. This connection was implemented using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SwiftNIO,&lt;/code&gt; offers native Swift Concurrency APIs and integrates well with the rest of the server ecosystem. The benefit of using Swift Concurrency for building such client is that it can make use of &lt;a href=&quot;https://developer.apple.com/videos/play/wwdc2023/10170/&quot;&gt;structured concurrency&lt;/a&gt; which brings cancellation, executor awareness, and simple integration with &lt;a href=&quot;https://github.com/apple/swift-distributed-tracing&quot;&gt;distributed tracing&lt;/a&gt; in the future.&lt;/p&gt;
&lt;p&gt;The focus during the project was implementing the Memcache &lt;a href=&quot;https://github.com/memcached/memcached/wiki/MetaCommands&quot;&gt;meta command protocol&lt;/a&gt; and offering basic &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;get&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;set&lt;/code&gt; functionalities.&lt;/p&gt;
&lt;p&gt;Below is a short example how the new &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MemcacheConnection&lt;/code&gt; type can be used to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;set&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;get&lt;/code&gt; a value for a given key:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// Instantiate a new MemcacheConnection with host, port, and event loop group&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;memcacheConnection&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;MemcacheConnection&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;host&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;127.0.0.1&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;11211&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;eventLoopGroup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;singleton&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Initialize the service group&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;serviceGroup&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ServiceGroup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;services&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;memcacheConnection&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;withThrowingTaskGroup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;of&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Void&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;group&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;group&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;addTask&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;serviceGroup&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Set a value for a key.&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;setValue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;bar&quot;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;memcacheConnection&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;foo&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;setValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Get the value for a key.&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Specify the expected type for the value returned from Memcache.&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;getValue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;memcacheConnection&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;foo&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;After finishing the foundational work to implement the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;get&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;set&lt;/code&gt; commands, support for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;delete&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;append&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;prepend&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;increment&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;decrement&lt;/code&gt; was added. Lastly, support for checking and updating the time-to-live for keys was added.&lt;/p&gt;
&lt;p&gt;The new &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MemcacheConnection&lt;/code&gt; type lays the ground work to implement a higher-level &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MemcacheClient&lt;/code&gt; that offers additional functionality such as connection pooling, retries, key distribution across nodes and more. However, implementing such a client was out of scope for this years GSoC project.&lt;/p&gt;
&lt;p&gt;If youd like to learn more about this project and Delkhazs experience, see &lt;a href=&quot;https://forums.swift.org/t/gsoc-2023-swift-memcache-gsoc-project-kickoff/64932&quot;&gt;this thread&lt;/a&gt; on the Swift forums.&lt;/p&gt;
&lt;h3 id=&quot;implement-incremental-re-parsing-in-swiftparser&quot;&gt;Implement Incremental Re-Parsing in SwiftParser&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Mentee: &lt;a href=&quot;https://github.com/StevenWong12&quot;&gt;Ziyang Huang&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Mentor: &lt;a href=&quot;https://github.com/ahoppen&quot;&gt;Alex Hoppen&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This project aimed to improve the performance of the &lt;a href=&quot;https://github.com/apple/swift-syntax/tree/main/Sources/SwiftParser&quot;&gt;SwiftParser&lt;/a&gt; for scenarios like editor syntax highlighting, where minor edits are applied to the file. By adding incremental parsing and re-using parts of the syntax tree that remain unchanged, large performance improvements can be made.&lt;/p&gt;
&lt;p&gt;The most challenging part of this project was to make sure we parse the source files correctly. Considering the code snippet below:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nf&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;someLabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;switch&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;This source is parsed as a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FunctionCallExprSyntax&lt;/code&gt; and a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LabeledStmtSyntax&lt;/code&gt;. When we remove the “&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;switch x&lt;/code&gt;” part of this code, a naïve implementation could reuse &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;foo() {}&lt;/code&gt; as a function call since the edit didnt touch it. But this is not correct since the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;someLabel&lt;/code&gt; block now became a labeled trailing closure of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;foo() {}&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;To solve this problem, we collect some additional information for every syntax node during the initial parse to mark the potentially affected range for each node. That information is used to correctly re-parse the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;foo()&lt;/code&gt; function call and include &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;someLabel&lt;/code&gt; as a labeled trailing closure in the call.&lt;/p&gt;
&lt;p&gt;The implementation speeds up parsing by about &lt;strong&gt;10x&lt;/strong&gt; when we parse source incrementally while &lt;strong&gt;only incurring a 2~3% of performance loss&lt;/strong&gt; during normal parsing.&lt;/p&gt;
&lt;p&gt;If youd like to read more about this project and Ziyangs experience in his own words, head over to &lt;a href=&quot;https://forums.swift.org/t/gsoc-2023-my-gsoc-experience/67340&quot;&gt;his GSoC experience post&lt;/a&gt; on the Swift forums.&lt;/p&gt;
&lt;h3 id=&quot;key-path-inference-and-diagnostic-improvements&quot;&gt;Key Path Inference and Diagnostic Improvements&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Mentee: &lt;a href=&quot;https://github.com/amritpan&quot;&gt;Amritpan Kaur&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Mentor: &lt;a href=&quot;https://github.com/xedin?tab=repositories&quot;&gt;Pavel Yaskevich&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This project was focused on performance and diagnostic improvements to type-checking of key path literal expressions as well as improvements to new features such as keypaths-as-functions introduced to the language by &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0249-key-path-literal-function-expressions.md&quot;&gt;SE-0249&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;During compilation, the key path expression root and value were type-checked sequentially to resolve a key path type from this context. However, the design of the type-checkers evaluation of key path component types, their relationships to each other, and key path capabilities results in hard to understand compiler errors and even failures to type-check some valid Swift code.&lt;/p&gt;
&lt;p&gt;Some of the problems with this approach can be illustrated by the following code example:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;User&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Name&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Name&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;firstName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;WritableKeyPath&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;User&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(\&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;firstName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;The compiler produces the following error:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;path&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;WritableKeyPath&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;User&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&apos;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cannot&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;be&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;converted&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;contextual&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;KeyPath&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;User&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&apos;&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(\&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;firstName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;^&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;There are multiple issues with this error diagnostic: contextual type is actually &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WritableKeyPath&lt;/code&gt; and key path should be inferred as read-only, the source information is lost and the compiler is unenable to point out a problem with an argument to a call to the function &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;test&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;To address these and other issues, we explored a different design for key path literal expression type-checking: infer the root type of the key path first and propagate that information to the components and infer capability based on the components before setting the type for the key path expression. This made it a lot easier to diagnose contextual type failures and support previously failing conversions. This approach improves the performance as well because the literal is resolved only if the context expects a key path and root type is either provided by the developer explicitly or is able to be inferred from the context.&lt;/p&gt;
&lt;p&gt;With the new approach implemented the compiler now produces the following diagnostic:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cannot&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;convert&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;of&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;KeyPath&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;User&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&apos;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;expected&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;argument&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;WritableKeyPath&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;User&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&apos;&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(\&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;firstName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;^&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;If youd like to learn more about the details of this project, we recommend having a look at this excellent and &lt;a href=&quot;https://forums.swift.org/t/key-path-inference-and-diagnostic-improvements-an-update/69632&quot;&gt;very detailed writeup written by Amritpan&lt;/a&gt; on the forums.&lt;/p&gt;
&lt;h2 id=&quot;mentee-impressions&quot;&gt;Mentee Impressions&lt;/h2&gt;
&lt;p&gt;Its great to see what projects our GSoC participants accomplished this year! Even better though is seeing participants enjoy their time working with the Swift project, as a big part of Summer of Code is giving mentees (and mentors) a space to grow and learn about open source development.&lt;/p&gt;
&lt;p&gt;Here are a few impressions of the mentees about their experience:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Delkhaz (Swift Memcache):&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;As we wrap up this technical update, its a bittersweet moment for me to share that my formal journey as a Google Summer of Code student has reached its conclusion, but what an incredible journey its been. This transformative experience has enriched my understanding of open source development and honed my skills as a developer. I want to extend a heartfelt thank you to everyone who has been a part of this adventure with me.&lt;/p&gt;
&lt;p&gt;While this chapter may be closing, Im thrilled to announce that I will remain actively involved in the project. Im particularly excited about contributing toward taking this project to its v1 or production stage. So, this isnt a goodbye; its just the beginning of a new chapter. Looking forward to staying in touch and continuing this journey with all of you.&lt;/p&gt;
&lt;p&gt;Special thanks are in order for my mentor Franz, for his exceptional mentorship during my time in the program. His wisdom and insights in our weekly sessions have been nothing short of transformative for me as a developer. Whether it was navigating the complexities of open-source contributions or striving for the highest standards in our API development, Franzs guidance has been indispensable. Ive gained a multifaceted understanding of software development thanks to his continued support. I couldnt have asked for a more impactful mentorship experience, and for that, I am deeply grateful.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;strong&gt;Ziyang (Implement Incremental Re-Parsing in SwiftParser):&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;After measurement, our implementation speed up parsing about 10 times when we parse source incrementally while only bring 2~3% of performance loss to normal parsing. 🎉 🎉&lt;/p&gt;
&lt;p&gt;I also bring this feature to sourcekit-lsp and swift-stress-tester, it is really exciting to see my work can be actually put into use.&lt;/p&gt;
&lt;p&gt;Special thanks to my mentor Alex for the quick response, detailed reviews and inspiring ideas.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;strong&gt;Amritpan (Key Path inference and diagnostic improvements):&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;I enjoyed working on this project this year, primarily because it was a challenge that allowed me to deepen my understanding of the solver implementation, utilize improvements I made last year to the debug output, and make more impactful changes to the compiler codebase.&lt;/p&gt;
&lt;p&gt;Refactoring the debug output last year helped me understand how the various pieces of information that the type checker collected were then evaluated to assign types from context. Taking a look at key path expression type checking failures revealed some of the fallibilities of the constraint system and solver and how various design decision choices could solve certain issues while causing others.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;We hope this writeup inspires you to either apply to work with us or become a mentor on the Swift project in a future!&lt;/p&gt;
&lt;p&gt;We are always looking for ideas, mentors, and general input about how we can make Swifts ecosystem more inclusive and easier to participate in. If you have some ideas, would like to become a mentor in future editions, or if youre just curious about other project ideas that were floated during previous editions, visit the &lt;a href=&quot;https://forums.swift.org/c/development/gsoc/98&quot;&gt;dedicated GSoC category&lt;/a&gt; on the Swift forums. You can also check out &lt;a href=&quot;https://www.swift.org/blog/swift-summer-of-code-2022-summary/&quot;&gt;last years GSoC summary blog post&lt;/a&gt;, where we highlighted last years projects.&lt;/p&gt;
&lt;p&gt;If youre interested in participating as a mentee, keep an eye on the official &lt;a href=&quot;https://summerofcode.withgoogle.com/&quot;&gt;GSoC schedule&lt;/a&gt; and on the Swift forums &lt;a href=&quot;https://forums.swift.org/c/development/gsoc/98&quot;&gt;GSoC category&lt;/a&gt;.&lt;/p&gt;
</content>
</entry>
<entry>
<title>Swift OpenAPI Generator 1.0 Released</title>
<author>
<name>Swift.org</name>
</author>
<link href="https://swift.org/blog/swift-openapi-generator-1.0/"/>
<updated>2024-01-31T08:00:00-04:00</updated>
<id>https://swift.org/blog/swift-openapi-generator-1.0/</id>
<content type="html">&lt;p&gt;Were happy to announce the stable 1.0 release of &lt;a href=&quot;https://github.com/apple/swift-openapi-generator&quot;&gt;Swift OpenAPI Generator&lt;/a&gt;!&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://openapis.org&quot;&gt;OpenAPI&lt;/a&gt; is an open standard for describing the behavior of HTTP services with a rich ecosystem of tooling. One thing OpenAPI is particularly known for is tooling to generate &lt;em&gt;interactive&lt;/em&gt; documentation. But the core motivation of OpenAPI is &lt;em&gt;code-generation&lt;/em&gt;, which allows adopters to use an API-first approach to server development and, because many existing services document their API in this format, allows client developers to generate type-safe, idiomatic code to call these APIs.&lt;/p&gt;
&lt;!--read more--&gt;
&lt;p&gt;Many real-world APIs have hundreds of operations, each with rich request and response types, header fields, parameters, and more. Writing and maintaining this code for every operation can be repetitive, verbose, and error-prone.&lt;/p&gt;
&lt;p&gt;Swift OpenAPI Generator is a Swift package plugin that generates the code required to make API calls and implement API servers. The code is automatically generated at build-time, so its always in sync with the OpenAPI document and doesnt need to be committed to your source repository.&lt;/p&gt;
&lt;p&gt;Since the initial &lt;a href=&quot;https://www.swift.org/blog/introducing-swift-openapi-generator&quot;&gt;release&lt;/a&gt; six months ago, the project received over 250 pull requests, from more than 20 contributors, and has gained several new features and a simpler API.&lt;/p&gt;
&lt;h2 id=&quot;feature-highlights&quot;&gt;Feature Highlights&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Works with OpenAPI Specification versions 3.0 and 3.1.&lt;/li&gt;
&lt;li&gt;Streaming request and response bodies, backed by AsyncSequence, enabling use cases such as JSON event streams, and large payloads without buffering.&lt;/li&gt;
&lt;li&gt;Support for common content types, including JSON, multipart, URL-encoded form, base64, plain text, and raw bytes; all represented as value types with type-safe properties.&lt;/li&gt;
&lt;li&gt;Flexible client, server, and middleware abstractions, decoupling the generated code from the HTTP client library and web framework.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;a-quick-look&quot;&gt;A Quick Look&lt;/h2&gt;
&lt;p&gt;Consider a fictitious HTTP server that provides a single API endpoint to return a personalized greeting:&lt;/p&gt;
&lt;div class=&quot;language-console highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;go&quot;&gt;% curl &apos;https://example.com/api/greet?name=Jane&apos;
{
&quot;message&quot;: &quot;Hello, Jane&quot;
}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;This service can be described using the following OpenAPI document:&lt;/p&gt;
&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;na&quot;&gt;openapi&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;3.1.0&apos;&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;GreetingService&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;version&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;1.0.0&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;servers&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;https://example.com/api&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Example service deployment.&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;paths&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;/greet&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;operationId&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;getGreeting&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;parameters&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;name&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;required&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;query&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;The name used in the returned greeting.&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;schema&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;string&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;responses&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;200&apos;&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;A success response with a greeting.&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;application/json&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;schema&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;$ref&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;#/components/schemas/Greeting&apos;&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;components&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;schemas&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;Greeting&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;object&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;A value with the greeting contents.&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;properties&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;string&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;The string representation of the greeting.&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;required&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;message&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Swift OpenAPI Generator can be configured to generate:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Code to make type-safe requests to an API server with any HTTP client library.&lt;/li&gt;
&lt;li&gt;Code to bootstrap an HTTP server with any web framework using business logic that is decoupled from the network requests.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;generated-client-api&quot;&gt;Generated Client API&lt;/h3&gt;
&lt;p&gt;The generated code provides a type, named &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Client&lt;/code&gt;, which provides a method for each operation defined in the OpenAPI document and can be used with any HTTP library that provides an integration package for Swift OpenAPI Generator.&lt;/p&gt;
&lt;p&gt;The plugin produces the generated code at build time in a location determined by the build system. To use the generated code in your project, simply create a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Client&lt;/code&gt; by providing the server URL and HTTP transport youd like to use.&lt;/p&gt;
&lt;p&gt;The following example creates a Greeting Service client that uses URLSession to make the underlying HTTP requests.&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;OpenAPIURLSession&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Foundation&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;serverURL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;URL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;http://localhost:8080/api&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;transport&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;URLSessionTransport&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;getGreeting&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ok&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h3 id=&quot;generated-server-api-stubs&quot;&gt;Generated Server API Stubs&lt;/h3&gt;
&lt;p&gt;The generated code provides a Swift protocol, named &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;APIProtocol&lt;/code&gt;, which defines a method requirement for each operation defined in the OpenAPI document, and is designed to work with any web framework that provides an integration package for Swift OpenAPI Generator.&lt;/p&gt;
&lt;p&gt;To implement an API server, define a type that conforms to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;APIProtocol&lt;/code&gt;, providing just the business logic for each operation.&lt;/p&gt;
&lt;p&gt;To start the API server, use the generated &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;registerHandlers&lt;/code&gt; function to configure the HTTP server to route the HTTP requests to your handler.&lt;/p&gt;
&lt;p&gt;The following example implements the Greeting Service API in a type named &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Handler&lt;/code&gt; and configures a Vapor web server to serve the HTTP requests.&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;OpenAPIRuntime&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;OpenAPIVapor&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Vapor&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Handler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;APIProtocol&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getGreeting&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Operations&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getGreeting&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;throws&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Operations&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getGreeting&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Output&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;query&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;??&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Stranger&quot;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ok&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Hello, &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))))&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;@main&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Server&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;throws&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;app&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Vapor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Application&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;transport&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;VaporTransport&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;routesBuilder&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;handler&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Handler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;handler&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;registerHandlers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;transport&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;serverURL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;URL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;/api&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;execute&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h3 id=&quot;package-ecosystem&quot;&gt;Package Ecosystem&lt;/h3&gt;
&lt;p&gt;The Swift OpenAPI Generator project is split across multiple repositories to enable extensibility and minimize dependencies in your project.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-openapi-generator&quot;&gt;apple/swift-openapi-generator&lt;/a&gt;: Swift package plugin and CLI.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-openapi-runtime&quot;&gt;apple/swift-openapi-runtime&lt;/a&gt;: Runtime library used by the generated code.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-openapi-urlsession&quot;&gt;apple/swift-openapi-urlsession&lt;/a&gt;: Client transport using URLSession.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/swift-server/swift-openapi-async-http-client&quot;&gt;swift-server/swift-openapi-async-http-client&lt;/a&gt;: Client transport using AsyncHTTPClient.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/swift-server/swift-openapi-vapor&quot;&gt;swift-server/swift-openapi-vapor&lt;/a&gt;: Server transport using Vapor web framework.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/swift-server/swift-openapi-hummingbird&quot;&gt;swift-server/swift-openapi-hummingbird&lt;/a&gt;: Server transport using Hummingbird web framework.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;next-steps&quot;&gt;Next Steps&lt;/h2&gt;
&lt;p&gt;To get started, check out the &lt;a href=&quot;https://swiftpackageindex.com/apple/swift-openapi-generator/documentation&quot;&gt;documentation&lt;/a&gt;, which contains &lt;a href=&quot;https://swiftpackageindex.com/apple/swift-openapi-generator/tutorials/swift-openapi-generator&quot;&gt;step-by-step tutorials&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You can also experiment with &lt;a href=&quot;https://github.com/apple/swift-openapi-generator/blob/1.2.0/Examples/README.md&quot;&gt;example projects&lt;/a&gt; that use Swift OpenAPI Generator and integrate with other packages in the ecosystem.&lt;/p&gt;
&lt;p&gt;Or if you prefer to watch a video, check out &lt;a href=&quot;https://developer.apple.com/wwdc23/10171&quot;&gt;Meet Swift OpenAPI Generator&lt;/a&gt; from WWDC23.&lt;/p&gt;
&lt;p&gt;To ask a question, request a feature, or report a bug, &lt;a href=&quot;https://github.com/apple/swift-openapi-generator/issues/new/choose&quot;&gt;reach out to us on Github&lt;/a&gt; 👋.&lt;/p&gt;
</content>
</entry>
<entry>
<title>On-Crash Backtraces in Swift</title>
<author>
<name>Swift.org</name>
</author>
<link href="https://swift.org/blog/swift-5.9-backtraces/"/>
<updated>2023-11-08T06:00:00-04:00</updated>
<id>https://swift.org/blog/swift-5.9-backtraces/</id>
<content type="html">&lt;p&gt;The new Swift 5.9 release contains a number of helpful, new features for debugging code, including an out-of-process, interactive
crash handler to inspect crashes in real time, the ability to trigger
the debugger for just-in-time debugging, along with concurrency-aware
backtracing to make it easier to understand control flow in a program
that uses structured concurrency.&lt;/p&gt;
&lt;h3 id=&quot;out-of-process-crash-handling&quot;&gt;Out-of-Process Crash Handling&lt;/h3&gt;
&lt;p&gt;Prior to Swift 5.9, all you would get when your program fails is a message
from the parent process (often the shell) telling you that the child
process crashed:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;
&lt;pre class=&quot;terminal&quot; style=&quot;color:var(--color-term-normal); background:var(--color-term-background)&quot;&gt;
&lt;span class=&quot;shell&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;cmd&quot;&gt;./crash&lt;/span&gt;
I&amp;#39;m going to crash now
zsh: segmentation fault ./crash
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;On Apple platforms or on Windows, you could look at the crash logs
captured by the operating systems built-in crash reporter, but on
Linux thats typically all you had to go on.&lt;/p&gt;
&lt;p&gt;Now, instead of the opaque message above, the result looks something like this:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;
&lt;pre class=&quot;terminal&quot; style=&quot;color:var(--color-term-normal); background:var(--color-term-background)&quot;&gt;
&lt;span class=&quot;shell&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;cmd&quot;&gt;./crash&lt;/span&gt;
I&amp;#39;m going to crash now
💣 &lt;span style=&quot;color:var(--color-term-bright-red)&quot;&gt;Program crashed: Bad pointer dereference at 0x0000000000000004&lt;/span&gt;
Thread 0 crashed:
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt;0&lt;/span&gt; &lt;span style=&quot;color:var(--color-term-bright-cyan)&quot;&gt;reallyCrashMe()&lt;/span&gt;&lt;span style=&quot;color:var(--color-term-white)&quot;&gt; + 404&lt;/span&gt; in &lt;span style=&quot;color:var(--color-term-bright-magenta)&quot;&gt;crash&lt;/span&gt; at &lt;span style=&quot;color:var(--color-term-yellow)&quot;&gt;/Users/alastair/Source/crashDotSwift/crash.swift:4:15&lt;/span&gt;
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt; 2&lt;/span&gt;│ print(&amp;quot;I&amp;#39;m going to crash now&amp;quot;)
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt; 3&lt;/span&gt;│ let ptr = UnsafeMutablePointer&amp;lt;Int&amp;gt;(bitPattern: 4)!
&lt;span style=&quot;background:var(--color-term-highlight-background)&quot;&gt;&lt;span style=&quot;color:var(--color-term-bright-white)&quot;&gt;&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt; 4&lt;span style=&quot;color: var(--color-term-bright-white)&quot;&gt;│ ptr.pointee = 42&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color:var(--color-term-bright-red)&quot;&gt;&lt;/span&gt;
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt; 5&lt;/span&gt;│ }
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt; 6&lt;/span&gt;
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt;1&lt;/span&gt; &lt;span style=&quot;color:var(--color-term-bright-cyan)&quot;&gt;crashMe()&lt;/span&gt;&lt;span style=&quot;color:var(--color-term-white)&quot;&gt; + 12&lt;/span&gt; in &lt;span style=&quot;color:var(--color-term-bright-magenta)&quot;&gt;crash&lt;/span&gt; at &lt;span style=&quot;color:var(--color-term-yellow)&quot;&gt;/Users/alastair/Source/crashDotSwift/crash.swift:8:3&lt;/span&gt;
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt; 6&lt;/span&gt;
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt; 7&lt;/span&gt;│ func crashMe() {
&lt;span style=&quot;background:var(--color-term-highlight-background)&quot;&gt;&lt;span style=&quot;color:var(--color-term-bright-white)&quot;&gt;&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt; 8&lt;span style=&quot;color: var(--color-term-bright-white)&quot;&gt;│ reallyCrashMe()&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color:var(--color-term-bright-red)&quot;&gt;&lt;/span&gt;
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt; 9&lt;/span&gt;│ }
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt; 10&lt;/span&gt;
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt;2&lt;/span&gt; &lt;span style=&quot;color:var(--color-term-bright-cyan)&quot;&gt;main&lt;/span&gt;&lt;span style=&quot;color:var(--color-term-white)&quot;&gt; + 12&lt;/span&gt; in &lt;span style=&quot;color:var(--color-term-bright-magenta)&quot;&gt;crash&lt;/span&gt; at &lt;span style=&quot;color:var(--color-term-yellow)&quot;&gt;/Users/alastair/Source/crashDotSwift/crash.swift:11:1&lt;/span&gt;
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt; 9&lt;/span&gt;│ }
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt; 10&lt;/span&gt;
&lt;span style=&quot;background:var(--color-term-highlight-background)&quot;&gt;&lt;span style=&quot;color:var(--color-term-bright-white)&quot;&gt;&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt; 11&lt;span style=&quot;color: var(--color-term-bright-white)&quot;&gt;│ crashMe()&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color:var(--color-term-bright-red)&quot;&gt;&lt;/span&gt;
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt; 12&lt;/span&gt;
Press space to interact, D to debug, or any other key to quit (30s)
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Or if you run the same program within a pipeline (not attached to
a terminal), youll see a report like this:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;*** Program crashed: Bad pointer dereference at 0x0000000000000004 ***
Thread 0 crashed:
0 0x00000001045a3df0 reallyCrashMe() + 404 in crash at /Users/alastair/Source/crashDotSwift/crash.swift:4:15
1 [ra] 0x00000001045a3ea4 crashMe() + 12 in crash at /Users/alastair/Source/crashDotSwift/crash.swift:8:3
2 [ra] 0x00000001045a3c50 main + 12 in crash at /Users/alastair/Source/crashDotSwift/crash.swift:11:1
3 [ra] [system] 0x000000018705d058 start + 2224 in dyld
Registers:
x0 0x0000000000000001 1
x1 0x0000000000000000 0
x2 0x0000000000000000 0
x3 0x000060000016c1c0 c0 c1 28 fd 79 96 00 00 fb 07 00 00 00 00 00 00 ÀÁ(ýy···û·······
...
x26 0x0000000000000000 0
x27 0x0000000000000000 0
x28 0x0000000000000000 0
fp 0x000000016b85f310 20 f3 85 6b 01 00 00 00 a4 3e 5a 04 01 00 00 00 ó·k····¤&amp;gt;Z·····
lr 0x72268001045a3d44 8225402511295135044
sp 0x000000016b85f280 a0 f2 85 6b 01 00 00 00 00 00 00 00 00 00 00 00  ò·k············
pc 0x00000001045a3df0 28 01 00 f9 fd 7b 49 a9 ff 83 02 91 c0 03 5f d6 (··ùý{I©ÿ···À·_Ö
Images (42 omitted):
0x00000001045a00000x00000001045a4000 6776aba03ad432b68bc57220ac4e6ef8 crash /Users/alastair/Source/crashDotSwift/crash
0x00000001870570000x00000001870ea874 ee3f4181cec538c2b8a84d310be33491 dyld /usr/lib/dyld
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;This new feature greatly improves the on-crash debugging experience on Linux, where it is on by default. It is useful on macOS as well, but must be manually
enabled. It is not presently supported on Windows.&lt;/p&gt;
&lt;h3 id=&quot;interactive-backtraces&quot;&gt;Interactive Backtraces&lt;/h3&gt;
&lt;p&gt;You might be wondering about the message on the last line of the
in-terminal backtrace above, where it says:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Press space to interact, D to debug, or any other key to quit (30s)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Often when developing a program at the terminal, you might find that
the program crashes, but you arent able to reproduce the problem.
Without a suitable crash log, that can be very frustrating — you know
your program has a bug, but you dont know what it was or how to
reproduce it.&lt;/p&gt;
&lt;p&gt;The idea behind this feature is that it leaves the program suspended
(by default for 30 seconds, but this is configurable) and provides you
with the opportunity to either attach a debugger, or perform some
additional inspection of the crashed process.&lt;/p&gt;
&lt;p&gt;If you tap the spacebar when this prompt appears, you will be
presented with a simple command prompt that allows you to change the
backtracer settings, generate a new backtrace, list loaded images,
display register and memory contents, and get a listing of all of the
threads in the process. Typing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;help&lt;/code&gt; at the prompt will bring up a
list of available commands:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;
&lt;pre class=&quot;terminal&quot; style=&quot;color:var(--color-term-normal); background:var(--color-term-background)&quot;&gt;
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;help
Available commands:
backtrace Display a backtrace.
bt Synonym for backtrace.
debug Attach the debugger.
exit Exit interaction, allowing program to crash normally.
help Display help.
images List images loaded by the program.
mem Synonym for memory.
memory Inspect memory.
process Show information about the process.
quit Synonym for exit.
reg Synonym for registers.
registers Display the registers.
set Set or show options.
thread Show or set the current thread.
threads Synonym for process.
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;If you use the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;debug&lt;/code&gt; command or press &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;D&lt;/code&gt; at the prompt, the
backtracer will help you to attach a debugger to your program.
Exactly what happens here is platform-dependent.&lt;/p&gt;
&lt;p&gt;If you press any other key, or if the 30 second timer runs down, the
program will be allowed to crash normally.&lt;/p&gt;
&lt;p&gt;By default, the interactive feature will trigger if your programs
standard input and output are both attached to a terminal. In many
cases, this means youll get the right behavior automatically if
youre running in a CI system or as part of an automated script,
as those tend to run with the programs output redirected to a
pipe or a file.&lt;/p&gt;
&lt;p&gt;In situations where you do not want this feature enabled, you can
explicitly disable it by setting the environment variable
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SWIFT_BACKTRACE&lt;/code&gt; to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;interactive=no&lt;/code&gt;. You can also disable the color
output with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;color=no&lt;/code&gt;, as well as combine multiple options like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;interactive=no,color=no&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&quot;structured-concurrency-support&quot;&gt;Structured Concurrency Support&lt;/h3&gt;
&lt;p&gt;The backtracer is concurrency-aware and will correctly step back
through asynchronous frames. For example, given the program:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;level&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;level&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;ptr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;UnsafeMutablePointer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;bitPattern&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;ptr&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pointee&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;42&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;@main&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;CrashAsync&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;level&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;the backtrace will look like:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;
&lt;pre class=&quot;terminal&quot; style=&quot;color:var(--color-term-normal); background:var(--color-term-background)&quot;&gt;
&lt;span class=&quot;shell&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;cmd&quot;&gt;./crashAsync&lt;/span&gt;
💣 &lt;span style=&quot;color:var(--color-term-bright-red)&quot;&gt;Program crashed: Bad pointer dereference at 0x0000000000000004&lt;/span&gt;
Thread 1 crashed:
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt;0&lt;/span&gt; &lt;span style=&quot;color:var(--color-term-bright-cyan)&quot;&gt;level(n:)&lt;/span&gt;&lt;span style=&quot;color:var(--color-term-white)&quot;&gt; + 308&lt;/span&gt; in &lt;span style=&quot;color:var(--color-term-bright-magenta)&quot;&gt;crashAsync&lt;/span&gt; at &lt;span style=&quot;color:var(--color-term-yellow)&quot;&gt;/Users/alastair/Source/crashDotSwift/crashAsync.swift:6:17&lt;/span&gt;
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt; 4&lt;/span&gt;│ } else {
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt; 5&lt;/span&gt;│ let ptr = UnsafeMutablePointer&amp;lt;Int&amp;gt;(bitPattern: 4)!
&lt;span style=&quot;background:var(--color-term-highlight-background)&quot;&gt;&lt;span style=&quot;color:var(--color-term-bright-white)&quot;&gt;&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt; 6&lt;span style=&quot;color:var(--color-term-bright-white)&quot;&gt;│ ptr.pointee = 42&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color:var(--color-term-bright-red)&quot;&gt;&lt;/span&gt;
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt; 7&lt;/span&gt;│ }
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt; 8&lt;/span&gt;│ }
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt;1&lt;/span&gt; &lt;span style=&quot;color:var(--color-term-bright-cyan)&quot;&gt;level(n:)&lt;/span&gt; in &lt;span style=&quot;color:var(--color-term-bright-magenta)&quot;&gt;crashAsync&lt;/span&gt; at &lt;span style=&quot;color:var(--color-term-yellow)&quot;&gt;/Users/alastair/Source/crashDotSwift/crashAsync.swift:3&lt;/span&gt;
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt; 1&lt;/span&gt;│ func level(n: Int) async {
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt; 2&lt;/span&gt;│ if n &amp;lt; 5 {
&lt;span style=&quot;background:var(--color-term-highlight-background)&quot;&gt;&lt;span style=&quot;color:var(--color-term-bright-white)&quot;&gt;&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt; 3&lt;span style=&quot;color:var(--color-term-bright-white)&quot;&gt;│ await level(n: n + 1)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color:var(--color-term-bright-red)&quot;&gt;&lt;/span&gt;
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt; 4&lt;/span&gt;│ } else {
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt; 5&lt;/span&gt;│ let ptr = UnsafeMutablePointer&amp;lt;Int&amp;gt;(bitPattern: 4)!
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt;2&lt;/span&gt; &lt;span style=&quot;color:var(--color-term-bright-cyan)&quot;&gt;level(n:)&lt;/span&gt; in &lt;span style=&quot;color:var(--color-term-bright-magenta)&quot;&gt;crashAsync&lt;/span&gt; at &lt;span style=&quot;color:var(--color-term-yellow)&quot;&gt;/Users/alastair/Source/crashDotSwift/crashAsync.swift:3&lt;/span&gt;
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt;3&lt;/span&gt; &lt;span style=&quot;color:var(--color-term-bright-cyan)&quot;&gt;level(n:)&lt;/span&gt; in &lt;span style=&quot;color:var(--color-term-bright-magenta)&quot;&gt;crashAsync&lt;/span&gt; at &lt;span style=&quot;color:var(--color-term-yellow)&quot;&gt;/Users/alastair/Source/crashDotSwift/crashAsync.swift:3&lt;/span&gt;
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt;4&lt;/span&gt; &lt;span style=&quot;color:var(--color-term-bright-cyan)&quot;&gt;level(n:)&lt;/span&gt; in &lt;span style=&quot;color:var(--color-term-bright-magenta)&quot;&gt;crashAsync&lt;/span&gt; at &lt;span style=&quot;color:var(--color-term-yellow)&quot;&gt;/Users/alastair/Source/crashDotSwift/crashAsync.swift:3&lt;/span&gt;
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt;5&lt;/span&gt; &lt;span style=&quot;color:var(--color-term-bright-cyan)&quot;&gt;static CrashAsync.main()&lt;/span&gt; in &lt;span style=&quot;color:var(--color-term-bright-magenta)&quot;&gt;crashAsync&lt;/span&gt; at &lt;span style=&quot;color:var(--color-term-yellow)&quot;&gt;/Users/alastair/Source/crashDotSwift/crashAsync.swift:13&lt;/span&gt;
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt; 11&lt;/span&gt;│ struct CrashAsync {
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt; 12&lt;/span&gt;│ static func main() async {
&lt;span style=&quot;background:var(--color-term-highlight-background)&quot;&gt;&lt;span style=&quot;color:var(--color-term-bright-white)&quot;&gt;&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt; 13&lt;span style=&quot;color:var(--color-term-bright-white)&quot;&gt;│ await level(n: 1)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color:var(--color-term-bright-red)&quot;&gt;&lt;/span&gt;
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt; 14&lt;/span&gt;│ }
&lt;span style=&quot;color:var(--color-term-gray)&quot;&gt; 15&lt;/span&gt;│ }
Press space to interact, D to debug, or any other key to quit (30s)
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;On Apple platforms, this feature has no special requirements, but for
other platforms the backtracer needs to be able to look up symbols
to determine whether or not a given frame is asynchronous. If the
necessary symbols are not available, the backtrace will follow the
normal program stack rather than the async activation chain. This
will usually result in it showing frames from the concurrency runtime,
which are unlikely to be helpful when debugging most types of problem.&lt;/p&gt;
&lt;h3 id=&quot;improving-readability&quot;&gt;Improving Readability&lt;/h3&gt;
&lt;p&gt;The new backtracer also has a number of options to improve readability.&lt;/p&gt;
&lt;p&gt;You can configure the maximum number of frames that the backtracer
will generate (the default is 64), but since you might also want to
see frames at the top of the stack, the backtracer also has a setting
for the number of frames to capture there (by default 16). This is
particularly handy if your program crashes due to excessive recursion,
as youll usually see both the recursion and the cause of it, without
being overwhelmed by thousands and thousands of frames.&lt;/p&gt;
&lt;p&gt;The backtracer also skips over system frames and Swift thunks by
default. These are usually not relevant except to compiler or runtime
engineers, and generally result in more confusing output for most
developers.&lt;/p&gt;
&lt;p&gt;Additionally, the backtracer will automatically demangle both Swift
and C++ mangled names.&lt;/p&gt;
&lt;h3 id=&quot;summary&quot;&gt;Summary&lt;/h3&gt;
&lt;p&gt;The new on-crash debugging options in Swift 5.9 help you
debug your programs when they misbehave. The backtracer has a
number of helpful features including:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Out-of-process crash handling&lt;/li&gt;
&lt;li&gt;Smart, in-line display of program source, where available&lt;/li&gt;
&lt;li&gt;The option to pause and inspect your crashed program, or even
trigger the debugger for just-in-time debugging&lt;/li&gt;
&lt;li&gt;Support for Swift Concurrency&lt;/li&gt;
&lt;li&gt;Support for C++ name mangling in addition to Swift&lt;/li&gt;
&lt;li&gt;Colorized output for readability&lt;/li&gt;
&lt;li&gt;Expanded configuration options (&lt;a href=&quot;https://github.com/apple/swift/blob/main/docs/Backtracing.rst&quot;&gt;see
documentation&lt;/a&gt;).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The new feature is enabled by default on Linux and can be enabled for macOS (&lt;a href=&quot;https://github.com/apple/swift/blob/main/docs/Backtracing.rst&quot;&gt;see
documentation&lt;/a&gt;).
There is no Windows support at present.&lt;/p&gt;
</content>
</entry>
<entry>
<title>Introducing Packages on Swift.org</title>
<author>
<name>Swift.org</name>
</author>
<link href="https://swift.org/blog/packages-page/"/>
<updated>2023-11-01T06:30:00-04:00</updated>
<id>https://swift.org/blog/packages-page/</id>
<content type="html">&lt;p&gt;Today, Swift.org gains a useful, new &lt;a href=&quot;/packages&quot;&gt;top-level Packages page&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The page provides a streamlined entry to exploring the Swift package ecosystem. It has common categories like &lt;a href=&quot;/packages/server.html&quot;&gt;server&lt;/a&gt;, &lt;a href=&quot;/packages/networking.html&quot;&gt;networking&lt;/a&gt;, &lt;a href=&quot;/packages/testing.html&quot;&gt;testing&lt;/a&gt;, and &lt;a href=&quot;/packages/logging.html&quot;&gt;logging&lt;/a&gt;, as well as categories of interest like &lt;a href=&quot;/packages/macros.html&quot;&gt;packages containing macros&lt;/a&gt;. When you select a category, it provides a sample of some widely-used packages for that category, with information to help you explore further. Its a great way to get a sense of the variety of packages available for Swift.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/packages-page-blog/package-categories.png&quot; alt=&quot;A screenshot of the packages page, showing four individual package cards in a grid&quot; style=&quot;border: 1px solid #ddd;&quot; /&gt;
&lt;em&gt;The package lists give you relevant information at a glance.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The package lists are powered by the &lt;a href=&quot;https://swiftpackageindex.com/&quot;&gt;Swift Package Index&lt;/a&gt;, thanks to the &lt;a href=&quot;/blog/swift-package-index-developer-spotlight/&quot;&gt;sponsorship and support of Apple&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;community-showcase&quot;&gt;Community Showcase&lt;/h2&gt;
&lt;p&gt;In addition to finding common categories of packages, you can also browse new and interesting work from across the Swift package ecosystem with the &lt;a href=&quot;/packages/showcase.html&quot;&gt;Community Showcase&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The Community Showcase contains a rotating selection of packages being discussed by the Swift community. Anyone can nominate a package in &lt;a href=&quot;https://forums.swift.org/t/nominations-for-the-packages-community-showcase-on-swift-org/68168&quot;&gt;this forum thread&lt;/a&gt;, and nominations will be reviewed monthly by the &lt;a href=&quot;/website-workgroup/&quot;&gt;Swift Website Workgroup&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The new &lt;a href=&quot;/packages&quot;&gt;Packages page&lt;/a&gt; is an exciting step in growing a valuable and thriving package ecosystem for the benefit of all Swift developers.&lt;/p&gt;
</content>
</entry>
<entry>
<title>Swift Everywhere: Using Interoperability to Build on Windows</title>
<author>
<name>Swift.org</name>
</author>
<link href="https://swift.org/blog/swift-everywhere-windows-interop/"/>
<updated>2023-10-13T06:00:00-04:00</updated>
<id>https://swift.org/blog/swift-everywhere-windows-interop/</id>
<content type="html">&lt;p&gt;&lt;em&gt;This post was originally published at &lt;a href=&quot;https://speakinginswift.substack.com/p/interoperability-swifts-super-power&quot;&gt;Speaking in Swift by The Browser Company&lt;/a&gt; under the title “Interoperability: Swifts Super Power”.&lt;/em&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Swifts deliberate design choices over the years has resulted in a language that showcases how flexibility and compatibility does not need to come at the cost of usability. One of these design choices was Swifts focus on native interoperability with other languages. The flexibility that this enables makes it a joy to build rich, native experiences in Swift across a variety of environments.&lt;/p&gt;
&lt;p&gt;Traditionally when two languages need to interoperate, the function calls at the boundary between the two languages, also known as the Foreign Function Interface (FFI), will go through C using a library like libffi. This approach has some drawbacks such as incurred runtime performance costs and possibly extra boilerplate code. Instead, Swift embeds a copy of clang, the C and C++ compiler, which is able to directly translate between the languages avoiding penalties in code size and runtime performance. This level of interoperability composes wonderfully with existing systems and enables building complex software atop existing C libraries.&lt;/p&gt;
&lt;h2 id=&quot;the-windows-api&quot;&gt;The Windows API&lt;/h2&gt;
&lt;p&gt;When building native rich, native applications, one important use-case of interoperability is the ability to invoke platform-specific APIs. The Windows API surface reflects its extensive history; the requirement to maintain backwards compatibility has resulted in the accretion of APIs of different shapes. As such, a significant portion of the API is old and low-level enough to be defined in C.&lt;/p&gt;
&lt;p&gt;Since Swift uses clang rather than libffi to access C functions and data types, the Swift compiler uses a feature of clang known as (header) modules. Clang modules bundle a set of declarations together, identifying which declarations belong to a particular library, what other modules it may depend on, and what language the declarations are for. This is done by introducing an auxiliary file named &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;module.modulemap&lt;/code&gt; which contains the definition of the module.&lt;/p&gt;
&lt;p&gt;As such, to access the Windows APIs, we must modularize the Windows SDK into one or more clang modules. Fortunately this is not just a theoretical idea. The Swift toolchain contains a module definition for the Windows SDK in the form of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WinSDK&lt;/code&gt; clang module. To further refine these definitions, a Swift module overlays the clang definitions to provide more Swift friendly definitions in some cases. This exposes the C API surface area of the Windows SDK, and although does not contain all the more modern APIs, enables us to build a variety of command line and GUI apps on Windows.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/windows-interoperability-blog/swift-win32-gui-app.webp&quot; alt=&quot;A screenshot of a GUI application written using Swift/Win32, showing various standard controls&quot; style=&quot;max-width: 100%; height: auto; width: unset; margin: auto auto; display: block;&quot; /&gt;
&lt;em&gt;A GUI application using Swift/Win32, which provides a layer of Swift syntactic conveniences for older, C-based Windows UI APIs.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Modern APIs arent exposed using just C, however, and there are large portions of the Windows SDK which are exposed as C++. Realising there is a vast software ecosystem of C++ code that Swift developers may want access to, Swift 5.9 has introduced support for extending its language level interoperability to C++. Although virtual methods and copyable types are not yet available, as Swifts C++ interoperability matures, the native platform API surface available to Swift will also grow to include the majority of the C++ APIs in the Windows SDK.&lt;/p&gt;
&lt;p&gt;This C++ Interop enables a new set of libraries, beyond just the platform APIs, to become available to Swift. This allows Swift code to also take advantage of a variety of high-performance, cross-platform libraries written over decades by the C++ community. Firebase, for example, is a commonly used cloud computing service and is used in many modern products, including The Browser Companys browser, Arc. Although there is a Swift SDK for Firebase, it is limited to the Apple platforms and is based on Objective-C. However, there is also a cross-platform C++ SDK available. Now with C++ Interop, it is possible to expose this C++ SDK to Swift clients. Such a bridge is being built up with &lt;a href=&quot;https://github.com/compnerd/swift-firebase&quot;&gt;swift-firebase&lt;/a&gt;. Taking advantage of these C++ libraries cross-platform Swift software that would be difficult to build otherwise.&lt;/p&gt;
&lt;h2 id=&quot;component-object-model-com&quot;&gt;Component Object Model (COM)&lt;/h2&gt;
&lt;p&gt;While libraries are one mechanism for sharing code, they are not the only approach. Another style of code sharing is possible via inter-process communication (IPC), which allows two separate applications to communicate with each other and expose functionality to each other. One implementation of this technique that is prevalent on Windows is known as COM (Component Object Model).&lt;/p&gt;
&lt;p&gt;Microsoft explored this idea at a higher level in 1990, evolving DDE (Dynamic Data Exchange) into “Object Linking and Embedding” or OLE. The approach was to enable sharing of custom document handlers which could be embedded into new applications without having to rewrite parsers and renders for the formats. To share the implementation of applications across processes, an application could implement well-defined interfaces (e.g. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;IOleObject&lt;/code&gt;) that could be consumed by other processes. Eventually, OLE would evolve into what would become to be known as the Component Object Model, or COM.&lt;/p&gt;
&lt;p&gt;COMs design was flexible and powerful, and resulted in it being adopted as a common design pattern across a multitude of environments. CoreFoundation adopted it for its plugin model. CFLite, and various forks thereof, brought an implementation of COM to Linux. XPCOM (Cross-Platform Component Object Model) is similar to COM and would gain popularity through Mozillas extensive usage, as would Open Offices UNO technology. The model even found its way into driver development with the IOKit framework using a COM based model for kernel drivers.&lt;/p&gt;
&lt;p&gt;At COMs core is the idea of defining interfaces (which is normally done in the Interface Definition Language or IDL) that expose functionality to either through a library in the same address space or another process through IPC. Interfaces are identified by globally unique Interface IDs, and all inherit from a base interface called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;IUnknown&lt;/code&gt;. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;IUnknown&lt;/code&gt; exposes the two fundamental operations of COM:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;object lifetime management&lt;/li&gt;
&lt;li&gt;access to the objects functionality&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Similar to Swift, object lifetime management is implemented through reference counting, exposed in COM via the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AddRef&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Release&lt;/code&gt; methods. Access to the objects functionality is implemented via the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;QueryInterface&lt;/code&gt; method, allowing consumers to dynamically request for the objects functionality. Because consumers dynamically query for a specific COM interface, we cannot statically identify the operations at build time. But the cost is limited to a couple of pointer indirections, similar to C++s virtual methods, which gives COM a negligible performance overhead.&lt;/p&gt;
&lt;h2 id=&quot;com-support-in-swift-with-c-interop&quot;&gt;COM Support in Swift with C Interop&lt;/h2&gt;
&lt;p&gt;COM provides not only an interface for working with software dynamically but is also an Application Binary Interface, or ABI, which means it defines how parameters are passed and function calls are arranged. If we want to communicate with COM interfaces from Swift, we need to ensure that we conform to these ABI requirements. Given that the lingua franca for FFI is C, the ABI for COM can be expressed in C. So, as a first step, what does &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;IUnknown&lt;/code&gt; look like in C?&lt;/p&gt;
&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;typedef&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;IUnknownVtbl&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;ULONG&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;STDMETHODCALLTYPE&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;AddRef&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;IUnknown&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pUnk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;ULONG&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;STDMETHODCALLTYPE&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Release&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;IUnknown&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pUnk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;HRESULT&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;STDMETHODCALLTYPE&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;QueryInterface&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;IUnknown&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pUnk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;REFIID&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;riid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ppvObject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;IUnknownVtbl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;IUnknown&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;IUnknownVtbl&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lpVtbl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;IUnknown&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;If we were to describe this in Swift, we would expect this to be a protocol with a few constraints:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// typealias IID = WinSDK._GUID&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;typealias&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;REFIID&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;UnsafePointer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;IID&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;protocol&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;IUnknown&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;IID&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;IID&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;get&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;AddRef&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ULONG&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Release&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ULONG&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;QueryInterface&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;riid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;REFIID&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;ppvObject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;UnsafeMutablePointer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;UnsafeMutableRawPointer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;HRESULT&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;extension&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;IUnknown&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;QueryInterface&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Interface&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;IUnknown&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;throws&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Interface&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;: class&lt;/code&gt; on the protocol declaration adds a class-constraint on the protocol, indicating that any conforming type must be a class in Swift. The astute reader would spot the semantic parallels between &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;IUnknown&lt;/code&gt; and class-constrained types in Swift. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;class&lt;/code&gt; types in Swift employ reference counting through ARC, and COM does the same through MRC (manual reference counting), which explains the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AddRef&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Release&lt;/code&gt; methods. That leaves the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;QueryInterface&lt;/code&gt; method which is responsible for dynamically querying the COM Interface, which maps to Swifts casting operation. As it is not possible to provide a custom cast operation for a type in Swift, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;QueryInterface()&lt;/code&gt; method is a funny spelling for the as keyword. This shows that, conceptually, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;IUnknown&lt;/code&gt; is just another way to say “I have a class type in Swift that is implemented somewhere else”!&lt;/p&gt;
&lt;p&gt;Since COM concepts bridge so neatly to Swift, we can now build a bridge between COM and Swift. The associated code is available at &lt;a href=&quot;https://github.com/compnerd/swift-com&quot;&gt;Swift/COM&lt;/a&gt; and demonstrates the viability of interfacing with COM interfaces. As an example, Windows provides 3D acceleration through the DirectX APIs, which are exposed as a set of C++ and COM interfaces. &lt;a href=&quot;https://github.com/compnerd/DXSample&quot;&gt;DXSample&lt;/a&gt; uses the COM bridged interfaces to implement a 3D accelerated cube replete with shaders to demonstrate that this bridging is possible to accomplish and use in real world scenarios.&lt;/p&gt;
&lt;p&gt;Interfaces provide a definition of how you interact with some foreign type, one that may even be implemented in a different language. When using an interface implemented by someone else, such as a DirectX type, we receive a raw pointer to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;IUnknown&lt;/code&gt;. The raw pointer representation of the COM interface is cumbersome to use. Wrapping the pointer to abstract the indirection makes COM more approachable.&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;open&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ID3D12Object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;IUnknown&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;IID&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;IID&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;IID_ID3D12Object&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;SetName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;throws&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;perform&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;WinSDK&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;ID3D12Object&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pThis&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;CHECKED&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pThis&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pointee&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lpVtbl&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pointee&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;SetName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pThis&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;It is also possible to implement a COM interface in Swift, providing a Swift implementation that can be called from C/C++ code even, although this support is nascent and will evolve with Swifts C++ interoperability support. As COM has a strict ABI, once the object is constructed properly, it can easily be passed across the language boundary and, as such, a Swift type can easily be passed to any COM client.&lt;/p&gt;
&lt;h2 id=&quot;com-support-in-swift-with-c-interop-1&quot;&gt;COM Support in Swift with C++ Interop&lt;/h2&gt;
&lt;p&gt;The evolving C++ interop in Swift makes bridging COM to Swift simpler. The interface model in COM is very similar to classes in C++. A COM interface maps directly to a C++ class, and each function on a COM interface maps to a virtual method on the C++ type. For Windows APIs exposed as COM types, such as the DirectX APIs, the COM interfaces are primarily exposed as C++ classes with some optionality to get a C representation of the interface for bridging into other languages. As Swifts C++ interoperability support improves, it will be possible to import COM interfaces as C++ classes which bridge naturally to Swift types. This reduces the boilerplate we saw above when bridging to COM through C. As of this writing, Swifts C++ interop support for virtual method dispatch is under development and will soon be able to simplify COM access.&lt;/p&gt;
&lt;p&gt;Swifts work on C++ interoperability has helped our efforts to bridge Swift with COM in other ways as well, adding support for reference-counted foreign types in Swift with the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SWIFT_SHARED_REFERENCE&lt;/code&gt; annotation. Because COM provides a reference counted interface, we can attribute COM interfaces with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SWIFT_SHARED_REFERENCE&lt;/code&gt; to take advantage of ARC while importing types and get memory management for free, avoiding a class of memory safety issues.&lt;/p&gt;
&lt;h2 id=&quot;improving-swift-language-support-for-com&quot;&gt;Improving Swift Language Support for COM&lt;/h2&gt;
&lt;p&gt;Due to the current limitations with C++ interop, we must fallback to the common denominator for interop - C - when trying to bridge COM interfaces. When implementing wrapper types to work with COM interfaces, we notice that it requires a significant amount of boilerplate code. One of Swifts goals is to have clear, expressive code and this certainly takes away from that. An idea that merits a proper evolution proposal is extending the Swift language to support COM better through annotations. Imagine being able to declare a type as being accessible to COM by simply annotating it with an attribute as the follows:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;@COM&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;IID&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;IID_ICustomInterface&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;CLSID&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;CLSID_CustomInterface&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;open&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;CCustomInterface&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ICustomInterface&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;open&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;QueryInterface&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Interface&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;IUnknown&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;throws&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Interface&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;switch&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;riid&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pointee&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;IID_ICustomInterface&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;IID_IUnknown&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Unmanaged&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;Self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;passRetained&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;nil&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Swift macros could help alleviate some of this boilerplate, but in order to truly bridge the Swift type into COM, the object layout needs to be considered. Because COM is an ABI, how the object is represented in memory must be identical to that dictated by COM. Controlling the object layout impacts ABI and is not something that would be possible with macros alone. One way we could implement this COM attribute at the language level would be to add a tear-off entry to the object that would conform to the ABI requirements for COM as part of the Swift object layout (with an opt-in) enabling more transparent bridging to the system without having to manually re-construct the vtable.&lt;/p&gt;
&lt;p&gt;Swifts ongoing distributed actors work also aligns well with COM. Distributed COM (DCOM) allows for network transparency with COM objects and enables building robust distributed systems. Distributed actors do not mandate the wire format, which means that we could even re-use the standard wire protocol for DCOM (DCE/RPC). This would allow for native Swift applications on Windows to easily scale from command line applications to large scale distributed systems.&lt;/p&gt;
&lt;h2 id=&quot;interoperability-on-windows&quot;&gt;Interoperability on Windows&lt;/h2&gt;
&lt;p&gt;Swifts arsenal of interoperability tools makes it a potent language for building rich, native applications and libraries on existing platforms, and provides a great alternative to C and C++ with its improved memory safety and ergonomics. On Windows particularly, the interoperability features allow us to gain access to a very large set of the systems API. Best of all, since COM is used outside of the Windows ecosystem, improvements to Swifts integration with Windows system APIs, such as the native COM bridging described above, would also help other platforms! New features such as C++ Interoperability, macros, and distributed actors are opening up a whole new set of opportunities for applications to be written in a more portable fashion.&lt;/p&gt;
&lt;p&gt;This foray into Windows and our exploration of Swifts approach to interoperability has given us a good foundation on how Swifts interoperability tools allow us to build cross-platform applications that can access platform APIs.&lt;/p&gt;
</content>
</entry>
<entry>
<title>Debugging Improvements in Swift 5.9</title>
<author>
<name>Swift.org</name>
</author>
<link href="https://swift.org/blog/whats-new-swift-debugging-5.9/"/>
<updated>2023-09-28T07:00:00-04:00</updated>
<id>https://swift.org/blog/whats-new-swift-debugging-5.9/</id>
<content type="html">&lt;p&gt;Swift 5.9 introduced a number of new debugging features to the compiler and &lt;a href=&quot;https://lldb.llvm.org/&quot; title=&quot;LLDB project home page&quot;&gt;LLDB&lt;/a&gt; debugger.&lt;/p&gt;
&lt;p&gt;Here are three changes that can help with your everyday debugging workflows.&lt;/p&gt;
&lt;h3 id=&quot;faster-variable-inspection-with-p-and-po&quot;&gt;Faster variable inspection with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;p&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;po&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;LLDB provides the shorthand &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;p&lt;/code&gt; command alias to inspect variables and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;po&lt;/code&gt; to call the debugDescription property of objects. Originally, these were aliases for the rather heavyweight &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;expression&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;expression -O&lt;/code&gt; commands. In Swift 5.9, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;p&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;po&lt;/code&gt; command aliases have been redefined to the new &lt;a href=&quot;https://reviews.llvm.org/D138315&quot; title=&quot;LLVM review&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dwim-print&lt;/code&gt; command&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dwim-print&lt;/code&gt; command prints values using the most user-friendly implementation. “DWIM” is an acronym for “Do What I Mean”. Specifically, when printing variables, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dwim-print&lt;/code&gt; will use the same implementation as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;frame variable&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v&lt;/code&gt; instead of the more expensive expression evaluator.&lt;/p&gt;
&lt;p&gt;In addition to being faster, using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;p&lt;/code&gt; &lt;a href=&quot;https://reviews.llvm.org/D145609&quot; title=&quot;LLVM review&quot;&gt;no longer creates persistent result variables&lt;/a&gt; like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$R0&lt;/code&gt;, which are often unused in debugging sessions. Persistent result variables not only incur overhead but also retain any objects they contain, which can be an unexpected side effect for the program execution.&lt;/p&gt;
&lt;p&gt;Users who want persistent results on occasion can use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;expression&lt;/code&gt; (or a unique prefix such as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;expr&lt;/code&gt;) directly instead of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;p&lt;/code&gt;. If you wish to enable persistent results every time, you can take advantage of LLDBs handy alias feature and put the following into the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~/.lldbinit&lt;/code&gt; file:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;command unalias p
command alias p dwim-print --persistent-result on --
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dwim-print&lt;/code&gt; command also gives &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;po&lt;/code&gt; new functionality. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;po&lt;/code&gt; command can now print Swift objects &lt;em&gt;even when only given a raw address&lt;/em&gt;. When running &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;po &amp;lt;object-address&amp;gt;&lt;/code&gt;, LLDBs embedded Swift compiler will automatically evaluate the expression &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;unsafeBitCast(&amp;lt;object-address&amp;gt;, to: AnyObject.self)&lt;/code&gt; under the hood to produce the expected result.&lt;/p&gt;
&lt;p&gt;Before Swift 5.9:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;(lldb) po 0x00006000025c43d0
(Int) 105553155867600
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;With Swift 5.9:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;(lldb) po 0x00006000025c43d0
&amp;lt;MyApp.AppDelegate: 0x6000025c43d0&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h3 id=&quot;support-for-generic-type-parameters-in-expressions&quot;&gt;Support for generic type parameters in expressions&lt;/h3&gt;
&lt;p&gt;LLDB now supports referring to generic type parameters in expression evaluation. For example, given the following code:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;use&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// break here&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;use&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;use&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Hello!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Running &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;po T.self&lt;/code&gt;, when stopped in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;use&lt;/code&gt;, will print &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Int&lt;/code&gt; when coming in through the first call, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt; in the second.&lt;/p&gt;
&lt;p&gt;In addition to displaying the concrete type of the generic, you can use this to set conditions that look for concrete types. For example, if you add the condition &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T.self == String.self&lt;/code&gt; to the above breakpoint, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;use&lt;/code&gt; will only stop when the variable &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;t&lt;/code&gt; is a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt;. (Note this last example only works on nightly builds of the Swift 5.9 toolchain.)&lt;/p&gt;
&lt;p&gt;More details about the implementation of this feature can be found in the original &lt;a href=&quot;https://github.com/apple/llvm-project/pull/5715&quot;&gt;LLDB pull request&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;fine-grained-scope-information&quot;&gt;Fine-grained scope information&lt;/h3&gt;
&lt;p&gt;The Swift compiler now emits more precise lexical scopes in debug information, allowing the debugger to better distinguish between different variables, like the many variables named &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;x&lt;/code&gt; in the following example:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;AnyObject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// function parameter `x: AnyObject?`&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;guard&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// local variable `x: AnyObject`, which shadows the function argument `x`&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;In Swift 5.9, the compiler now uses more accurate &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ASTScope&lt;/code&gt; information to generate the lexical scope hierarchy in the debug information, which results in some behavior changes in the debugger.&lt;/p&gt;
&lt;p&gt;In the example below, the local variable &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;a&lt;/code&gt; is not yet in scope at the call site of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getInt()&lt;/code&gt; and will only be available after it has been assigned. With the debug information produced by previous versions of the Swift compiler, the debugger might have displayed uninitialized memory as the contents of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;a&lt;/code&gt; at the call site of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getInt()&lt;/code&gt;. In Swift 5.9, the variable &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;a&lt;/code&gt; only becomes visible after it has been initialized:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; 1 func getInt() -&amp;gt; Int { return 42 }
2
3 func f() {
4 let a = getInt()
^
5 print(a)
6 }
(lldb) p a
error: &amp;lt;EXPR&amp;gt;:3:1: error: cannot find &apos;a&apos; in scope
(lldb) n
3 func f() {
4 let a = getInt()
5 print(a)
^
6 }
(lldb) p a
42
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;!---
In fact, the Swift language&apos;s scoping rules allow some astonishing things to be done with variable bindings:
```swift
enum E&lt;T&gt; {
case A(T)
case B(T)
case C(String)
case D(T, T, T)
}
func f&lt;T&gt;(_ e: E&lt;T&gt;) -&gt; String {
switch e {
case .A(let a), .B(let a): return &quot;One variable \(a): T in scope&quot;
case .C(let a): return &quot;One variable \(a): String in scope&quot;
case .D(let a, _, let c): return &quot;One \(a): T and one \(c): T in scope&quot;
default: return &quot;Only the function argument e is in scope&quot;
}
}
```
All of these can be correctly disambiguated by LLDB thanks to lexical scope debug information.
---&gt;
&lt;p&gt;For more details, see the &lt;a href=&quot;https://github.com/apple/swift/pull/64941&quot;&gt;pull request&lt;/a&gt; that introduced this change.&lt;/p&gt;
&lt;h3 id=&quot;get-involved&quot;&gt;Get involved&lt;/h3&gt;
&lt;p&gt;If you want to learn more about Swift debugging and LLDB, provide feedback, or contribute to the tooling itself, join us in the &lt;a href=&quot;https://forums.swift.org/c/development/lldb/13&quot;&gt;LLDB section&lt;/a&gt; of the Swift development forums.&lt;/p&gt;
</content>
</entry>
<entry>
<title>Swift 5.9 Released</title>
<author>
<name>Swift.org</name>
</author>
<link href="https://swift.org/blog/swift-5.9-released/"/>
<updated>2023-09-18T07:00:00-04:00</updated>
<id>https://swift.org/blog/swift-5.9-released/</id>
<content type="html">&lt;p&gt;Swift 5.9 is now available! 🎉&lt;/p&gt;
&lt;p&gt;This is a major new release that &lt;strong&gt;adds an expressive macro system to the language&lt;/strong&gt; and introduces &lt;strong&gt;support for integrating Swift into C++ codebases&lt;/strong&gt; through bidirectional interoperability.&lt;/p&gt;
&lt;p&gt;It also introduces parameter packs, an improved expression evaluator while debugging, enhanced crash handling, Windows platform improvements, and more.&lt;/p&gt;
&lt;p&gt;Read on for a deep dive into changes to the language, standard library, tooling, platform support, and next steps for getting started with Swift 5.9.&lt;/p&gt;
&lt;p&gt;Thank you to everyone in the Swift community who made this release possible. Your Swift Forums discussions, bug reports, pull requests, educational content, and other contributions are always appreciated!&lt;/p&gt;
&lt;h2 id=&quot;language-and-standard-library&quot;&gt;Language and Standard Library&lt;/h2&gt;
&lt;p&gt;Swifts fundamental goal is to encourage code that is clear and concise, while remaining safe and efficient.&lt;/p&gt;
&lt;p&gt;This release adds three long-desired features that further that goal: a new macro system for more expressive libraries, parameter packs to make overloaded APIs natural to use, and new ownership features to offer more control over performance in low-level code.&lt;/p&gt;
&lt;h3 id=&quot;macros&quot;&gt;Macros&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/visions/macros.md&quot;&gt;Macros&lt;/a&gt; help developers reduce repetitive boilerplate and create more expressive libraries that can be distributed as a Swift package.&lt;/p&gt;
&lt;p&gt;Using a macro is easy and natural. Macros can either be expanded with a function-like freestanding &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#macroName&lt;/code&gt; syntax:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Font&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;#fontLiteral&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;SF Mono&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;14&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;weight&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;regular&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;or attached to declarations with an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@MacroName&lt;/code&gt; attribute:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// Move storage from the stored properties into a dictionary,&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// turning the stored properties into computed properties.&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;@DictionaryStorage&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Point&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;They work just like built-in language features but cant be mistaken for normal code.&lt;/p&gt;
&lt;p&gt;You write macros using a powerful and flexible approach: they are simply Swift functions that use the &lt;a href=&quot;https://github.com/apple/swift-syntax&quot;&gt;SwiftSyntax&lt;/a&gt; library to generate code to be inserted into the source file.&lt;/p&gt;
&lt;p&gt;Macros make it easy for your librarys users to adopt powerful capabilities that adapt to the code theyre used in, like &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0395-observability.md&quot;&gt;the new &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Observation&lt;/code&gt; module&lt;/a&gt;, which allows Swift classes to automatically notify other code when their properties change.&lt;/p&gt;
&lt;p&gt;The Swift community has been hard at work creating tools and frameworks that build upon macros. For some examples, take a look at &lt;a href=&quot;https://github.com/kishikawakatsumi/swift-power-assert&quot;&gt;swift-power-assert&lt;/a&gt;, &lt;a href=&quot;https://github.com/Matejkob/swift-spyable&quot;&gt;swift-spyable&lt;/a&gt;, &lt;a href=&quot;https://github.com/pointfreeco/swift-macro-testing&quot;&gt;swift-macro-testing&lt;/a&gt;, and &lt;a href=&quot;https://github.com/SwiftyLab/MetaCodable&quot;&gt;MetaCodable&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Swift 5.9 supports macros on macOS and Linux, with Windows support coming soon.&lt;/p&gt;
&lt;h3 id=&quot;parameter-packs&quot;&gt;Parameter packs&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0393-parameter-packs.md&quot;&gt;Parameter packs&lt;/a&gt; let you write generic types and functions which work over an arbitrary number of types.&lt;/p&gt;
&lt;p&gt;For example, without parameter packs, if you wanted to write a function called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;all&lt;/code&gt; to check whether any number of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Optional&lt;/code&gt; values are &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nil&lt;/code&gt;, you would need to write a separate overload for each argument length you wanted to support, creating an arbitrary upper limit:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;all&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;W1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;optional&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;W1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;W1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;all&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;W1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;W2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;optional1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;W1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;optional2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;W2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;W1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;W2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)?&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;all&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;W1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;W2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;W3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;optional1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;W1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;optional2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;W2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;optional3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;W3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;W1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;W2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;W3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)?&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;With parameter packs, you can express this API as a single function that has no upper limit, allowing you to pass any number of arguments:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;all&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;each&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Wrapped&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;optional&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;repeat&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;each&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Wrapped&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)?)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;repeat&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;each&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Wrapped&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)?&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Calling an API that uses parameter packs is intuitive and requires no extra work:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;double&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;bool&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;all&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;optionalInt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;optionalDouble&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;optionalString&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;optionalBool&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;double&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;bool&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;got a nil&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h3 id=&quot;ownership&quot;&gt;Ownership&lt;/h3&gt;
&lt;p&gt;Ownership features can help developers fine-tune memory management behavior in performance-critical code.&lt;/p&gt;
&lt;p&gt;The new &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0366-move-function.md&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;consume&lt;/code&gt; operator&lt;/a&gt; tells Swift to deinitialize a variable and transfer its contents without copying it. The &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0377-parameter-ownership-modifiers.md&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;consuming&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;borrowing&lt;/code&gt; parameter modifiers&lt;/a&gt; provide hints that Swift can use to eliminate unnecessary copying and reference-counting operations when passing a parameter. Finally, &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0390-noncopyable-structs-and-enums.md&quot;&gt;noncopyable structs and enums&lt;/a&gt; allow you to create types which, like a class, cant be meaningfully copied when assigned, but like a struct or enum, do not need to be reference-counted because only one storage location can own the instance at a time.&lt;/p&gt;
&lt;p&gt;These major features are the foundation for further evolution that puts more expressive power and performance control into your hands. Were excited about what you can do with Swift 5.9, and were working toward a future with a larger suite of variadic generics and ownership features.&lt;/p&gt;
&lt;h3 id=&quot;additional-features&quot;&gt;Additional Features&lt;/h3&gt;
&lt;p&gt;Swift 5.9 also includes smaller, quality-of-life changes to the language, like the ability to use &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0380-if-switch-expressions.md&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;if&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;switch&lt;/code&gt; as expressions&lt;/a&gt; for variable assignment and return values:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;statusBar&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hasConnection&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Disconnected&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;error&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lastError&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;localizedDescription&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Ready&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;A &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0386-package-access-modifier.md&quot;&gt;new &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;package&lt;/code&gt; access level&lt;/a&gt; lets other modules in the same package access APIs, but hides them from code outside the package. Its great for splitting up large modules into several smaller ones without exposing internals to the packages clients.&lt;/p&gt;
&lt;p&gt;Developers using Swift Concurrency may appreciate the &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0381-task-group-discard-results.md&quot;&gt;more convenient &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DiscardingTaskGroup&lt;/code&gt; types&lt;/a&gt; for task groups that dont generate results and the advanced &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0392-custom-actor-executors.md&quot;&gt;custom actor executors&lt;/a&gt; feature for controlling the exact environment that an actor is run in.&lt;/p&gt;
&lt;p&gt;A full list of Swift 5.9 Evolution proposals can be found at the end of this post.&lt;/p&gt;
&lt;h2 id=&quot;developer-experience&quot;&gt;Developer Experience&lt;/h2&gt;
&lt;h3 id=&quot;crash-handling&quot;&gt;Crash Handling&lt;/h3&gt;
&lt;p&gt;On Linux, the Swift runtime will now catch program crashes and Swift runtime errors and display a backtrace on the programs output. The backtracer is out-of-process and includes support for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;async&lt;/code&gt; functions.&lt;/p&gt;
&lt;p&gt;This feature is also available on macOS but is disabled by default. To enable it, set &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SWIFT_BACKTRACE=enable=yes&lt;/code&gt; and sign your program with the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;com.apple.security.get-task-allow&lt;/code&gt; entitlement.&lt;/p&gt;
&lt;h3 id=&quot;debugging&quot;&gt;Debugging&lt;/h3&gt;
&lt;p&gt;Swift 5.9 introduces new features to &lt;a href=&quot;https://lldb.llvm.org/&quot;&gt;LLDB&lt;/a&gt; and the Swift compiler aimed at making Swift debugging faster and more reliable.&lt;/p&gt;
&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;p&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;po&lt;/code&gt; commands now print local variables and properties as fast as the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;frame variable&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v&lt;/code&gt; commands by bypassing the Swift compiler when evaluating simple expressions.&lt;/p&gt;
&lt;p&gt;Swift expressions can now refer to generic type parameters. This allows setting a conditional breakpoint in a generic function that only triggers when a type parameter is instantiated with a specific concrete type.&lt;/p&gt;
&lt;p&gt;The debug info produced by the Swift compiler now more precisely scopes local variables, making it less likely to display variables backed by uninitialized memory in the debugger.&lt;/p&gt;
&lt;h2 id=&quot;ecosystem&quot;&gt;Ecosystem&lt;/h2&gt;
&lt;h3 id=&quot;c-interoperability&quot;&gt;C++ Interoperability&lt;/h3&gt;
&lt;p&gt;Swift 5.9 supports bidirectional interoperability with C++ and Objective-C++ for certain kinds of APIs.&lt;/p&gt;
&lt;p&gt;For example, if you have a C++ function like:&lt;/p&gt;
&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// Clang module &apos;PromptResponder&apos;&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#pragma once
#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&amp;lt;vector&amp;gt;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vector&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;generatePromptResponse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;you can call it directly from your Swift code:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;PromptResponder&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;codeLines&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;generatePromptResponse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Write Swift code that prints hello world&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;filter&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isEmpty&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;codeLines&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;line&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;C++ interoperability is actively evolving, with some aspects subject to change in future releases as the community gathers feedback from real world adoption in mixed Swift and C++ codebases.&lt;/p&gt;
&lt;p&gt;For information on enabling C++ interoperability and the supported language subset, please refer to the &lt;a href=&quot;/documentation/cxx-interop/&quot;&gt;documentation&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Special thanks to the &lt;a href=&quot;/cxx-interop-workgroup/&quot;&gt;C++ Interoperability Workgroup&lt;/a&gt; for their focus and dedication in supporting this feature.&lt;/p&gt;
&lt;h3 id=&quot;swift-package-manager&quot;&gt;Swift Package Manager&lt;/h3&gt;
&lt;p&gt;The &lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;Swift Package Manager&lt;/a&gt; has a number of improvements in Swift 5.9:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Packages can use the new &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;package&lt;/code&gt; access modifier, allowing access of symbols in another target / module within the same package without making them public. SwiftPM automatically sets the new compiler configuration to ensure this feature works out-of-the-box for packages.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CompilerPluginSupport&lt;/code&gt; module enables defining macro targets. Macro targets allow authoring and distributing custom Swift macros as APIs in a library.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The new &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.embedInCode&lt;/code&gt; resource rule allows embedding the contents of a resource into an executable by generating a byte array.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;allowNetworkConnections(scope:reason:)&lt;/code&gt; setting gives a command plugin permissions to access the network. Permissions can be scoped to Unix domain sockets as well as local or remote IP connections, with an option to limit by port. For non-interactive use cases, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--allow-network-connections&lt;/code&gt; command-line flag allows network connections for a particular scope.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;SwiftPM can now publish to a registry following the specification defined in &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0391-package-registry-publish.md&quot;&gt;SE-0391&lt;/a&gt;, as well as support signed packages, which may be required by a registry. Trust-on-first-use (TOFU) validation checks can now use signing identities in addition to fingerprints, and are enforced for source archives as well as package manifests.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;SwiftPM now supports cross compilation based on &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0387-cross-compilation-destinations.md#swift-sdk-bundles&quot;&gt;the Swift SDK bundle format&lt;/a&gt;. While the feature is still considered experimental, we invite users to try it out and provide feedback.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;See the &lt;a href=&quot;https://github.com/apple/swift-package-manager/blob/main/CHANGELOG.md#swift-59&quot;&gt;Swift Package Manager changelog&lt;/a&gt; for the complete list of changes.&lt;/p&gt;
&lt;h3 id=&quot;swift-syntax&quot;&gt;Swift Syntax&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-syntax&quot;&gt;swift-syntax&lt;/a&gt; is an essential tool for parsing Swift code and helps power the new macro system. This year, swift-syntax received a number of improvements:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Syntax node names are more consistent and accurately reflect the Swift language.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Error recovery in the new SwiftParser is greatly improved, leading to more precise error messages for incorrect or missing syntax.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Incremental parsing is now supported, allowing editors and other tools to only reparse those parts of a syntax tree that have changed.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The &lt;a href=&quot;https://swiftpackageindex.com/apple/swift-syntax&quot;&gt;documentation&lt;/a&gt; of swift-syntax has been greatly expanded.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Over the last year, swift-syntax has been a huge success as an open source project. Since the release of Swift 5.8, more than 30 distinct contributors have worked on the package, accounting for more than 30% of the commits. In addition, the community tool &lt;a href=&quot;https://swift-ast-explorer.com&quot;&gt;swift-ast-explorer.com&lt;/a&gt; is invaluable in exploring and understanding the SwiftSyntax tree. Thank you to everyone who contributed!&lt;/p&gt;
&lt;h3 id=&quot;server&quot;&gt;Server&lt;/h3&gt;
&lt;p&gt;Custom actor executors and other features from Swift 5.9 are making their way into the Swift on server ecosystem.&lt;/p&gt;
&lt;p&gt;The server workgroup also recently published their &lt;a href=&quot;/blog/sswg-update-2023/&quot;&gt;annual update for 2023&lt;/a&gt;, detailing plans to increase adoption of concurrency within key libraries, as well as other efforts.&lt;/p&gt;
&lt;h3 id=&quot;windows-platform&quot;&gt;Windows Platform&lt;/h3&gt;
&lt;p&gt;Windows support for Swift 5.9 greatly improves stability and the developer experience.&lt;/p&gt;
&lt;p&gt;The Windows installer now supports installation both before and after Visual Studio installation, and no longer requires repair after a Visual Studio upgrade. Initial work has also begun to enable multiple, parallel toolchains installed side-by-side on Windows.&lt;/p&gt;
&lt;p&gt;The Swift toolchain also added new flags (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-windows-sdk-root&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-windows-sdk-version&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-visualc-tools-root&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-visualc-tools-version&lt;/code&gt;) to help control the Windows SDK and Visual C++ tools that it builds against.&lt;/p&gt;
&lt;p&gt;The Windows SDK (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WinSDK&lt;/code&gt;) module saw improvements in coverage, enabling access to a wider set of system APIs. The Visual C++ (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;vcruntime&lt;/code&gt;) module was greatly restructured to support C++ interoperability.&lt;/p&gt;
&lt;p&gt;Structured Concurrency is now significantly more stable on Windows, eliminating stack overflows and other execution failures for common patterns such as iterating over an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AsyncStream&lt;/code&gt; with many elements.&lt;/p&gt;
&lt;p&gt;Improvements to path handling in the LSP and SwiftPM makes both of these tools more robust on Windows. LLDB also saw initial work towards improving support for Windows, enabling fundamental debugging workflows in LLDB on Windows. While still a work in progress, this will significantly improve the developer experience on Windows.&lt;/p&gt;
&lt;p&gt;Small improvements have also been made to reduce the size of the toolchain on Windows.&lt;/p&gt;
&lt;h2 id=&quot;next-steps&quot;&gt;Next Steps&lt;/h2&gt;
&lt;h3 id=&quot;downloads&quot;&gt;Downloads&lt;/h3&gt;
&lt;p&gt;Official binaries are &lt;a href=&quot;https://swift.org/download/&quot;&gt;available for download&lt;/a&gt; from &lt;a href=&quot;http://swift.org/&quot;&gt;Swift.org&lt;/a&gt; for macOS, Windows, and Linux. The Swift 5.9 compiler is also included in &lt;a href=&quot;https://apps.apple.com/app/xcode/id497799835&quot;&gt;Xcode 15&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;website&quot;&gt;Website&lt;/h3&gt;
&lt;p&gt;Swift.org has revamped certain key pages, including &lt;a href=&quot;/&quot;&gt;a richer home page&lt;/a&gt; and clearer &lt;a href=&quot;/install/&quot;&gt;download and install instructions&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If youre new to Swift or looking to dive deeper, check out the updated &lt;a href=&quot;/getting-started/&quot;&gt;Getting Started guides&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;language-guide&quot;&gt;Language Guide&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://docs.swift.org/swift-book/documentation/the-swift-programming-language/&quot;&gt;The Swift Programming Language&lt;/a&gt; book has been updated for Swift 5.9 and is now published with DocC.&lt;/p&gt;
&lt;p&gt;This is the official Swift guide and a great entry point for learning Swift.&lt;/p&gt;
&lt;p&gt;The Swift community also maintains a number of &lt;a href=&quot;/documentation/tspl/#translations&quot;&gt;translations&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;swift-evolution-appendix&quot;&gt;Swift Evolution Appendix&lt;/h2&gt;
&lt;p&gt;The following language, standard library, and Swift Package Manager proposals were accepted through the &lt;a href=&quot;https://github.com/apple/swift-evolution&quot;&gt;Swift Evolution&lt;/a&gt; process and &lt;a href=&quot;https://apple.github.io/swift-evolution/#?version=5.9&quot;&gt;implemented in Swift 5.9&lt;/a&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;SE-0366: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0366-move-function.md&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;consume&lt;/code&gt; operator to end the lifetime of a variable binding&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SE-0374: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0374-clock-sleep-for.md&quot;&gt;Add sleep(for:) to Clock&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SE-0377: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0377-parameter-ownership-modifiers.md&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;borrowing&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;consuming&lt;/code&gt; parameter ownership modifiers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SE-0380: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0380-if-switch-expressions.md&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;if&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;switch&lt;/code&gt; expressions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SE-0381: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0381-task-group-discard-results.md&quot;&gt;DiscardingTaskGroups&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SE-0382: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0382-expression-macros.md&quot;&gt;Expression Macros&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SE-0384: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0384-importing-forward-declared-objc-interfaces-and-protocols.md&quot;&gt;Importing Forward Declared Objective-C Interfaces and Protocols&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SE-0386: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0386-package-access-modifier.md&quot;&gt;New access modifier: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;package&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SE-0388: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0388-async-stream-factory.md&quot;&gt;Convenience Async[Throwing]Stream.makeStream methods&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SE-0389: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0389-attached-macros.md&quot;&gt;Attached Macros&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SE-0390: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0390-noncopyable-structs-and-enums.md&quot;&gt;Noncopyable structs and enums&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SE-0392: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0392-custom-actor-executors.md&quot;&gt;Custom Actor Executors&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SE-0393: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0393-parameter-packs.md&quot;&gt;Value and Type Parameter Packs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SE-0394: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0394-swiftpm-expression-macros.md&quot;&gt;Package Manager Support for Custom Macros&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SE-0395: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0395-observability.md&quot;&gt;Observation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SE-0396: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0396-never-codable.md&quot;&gt;Conform &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Never&lt;/code&gt; to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Codable&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SE-0397: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0397-freestanding-declaration-macros.md&quot;&gt;Freestanding Declaration Macros&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SE-0398: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0398-variadic-types.md&quot;&gt;Allow Generic Types to Abstract Over Packs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SE-0399: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0399-tuple-of-value-pack-expansion.md&quot;&gt;Tuple of value pack expansion&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SE-0400: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0400-init-accessors.md&quot;&gt;Init Accessors&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SE-0401: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0401-remove-property-wrapper-isolation.md&quot;&gt;Remove Actor Isolation Inference caused by Property Wrappers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SE-0402: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0402-extension-macros.md&quot;&gt;Generalize &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;conformance&lt;/code&gt; macros as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;extension&lt;/code&gt; macros&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
</entry>
<entry>
<title>SSWG 2023 Annual Update</title>
<author>
<name>Swift.org</name>
</author>
<link href="https://swift.org/blog/sswg-update-2023/"/>
<updated>2023-08-17T06:00:00-04:00</updated>
<id>https://swift.org/blog/sswg-update-2023/</id>
<content type="html">&lt;p&gt;Once a year, the Swift Server workgroup (SSWG) reflects on recent community accomplishments and lays out focus areas for the year ahead.&lt;/p&gt;
&lt;p&gt;Since &lt;a href=&quot;/blog/sswg-update/&quot;&gt;our last update&lt;/a&gt;, the Swift on server ecosystem has welcomed new projects, seen significant progress in the adoption of structured concurrency, improved its tooling, and more.&lt;/p&gt;
&lt;p&gt;Lets start by reviewing the progress made in 2022 then look ahead at the goals for the next 12 months.&lt;/p&gt;
&lt;h2 id=&quot;2022-in-review&quot;&gt;2022 in Review&lt;/h2&gt;
&lt;h3 id=&quot;continued-focus-on-growing-the-ecosystem&quot;&gt;Continued focus on growing the ecosystem&lt;/h3&gt;
&lt;p&gt;The ecosystem has seen a number of new libraries introduced including:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a &lt;a href=&quot;https://github.com/swift-server/swift-kafka-gsoc&quot;&gt;Kafka client library&lt;/a&gt; that started as a GSoC project&lt;/li&gt;
&lt;li&gt;a &lt;a href=&quot;https://github.com/apple/swift-cassandra-client&quot;&gt;Cassandra client library&lt;/a&gt; released by Apple and pitched to the &lt;a href=&quot;/sswg/incubation-process.html&quot;&gt;SSWG incubation process&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;a &lt;a href=&quot;https://github.com/GraphQLSwift/GraphQL&quot;&gt;GraphQL&lt;/a&gt; library pitched to the SSWG incubation process&lt;/li&gt;
&lt;li&gt;a &lt;a href=&quot;https://github.com/funcmike/rabbitmq-nio&quot;&gt;RabbitMQ library&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;a Memcached client library was proposed as a GSoC project&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There were also three new packages proposed and accepted into the SSWGs incubation process:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/swift-server/sswg/blob/main/proposals/0019-graphql.md&quot;&gt;GraphQL and Graphiti libraries&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/swift-server/sswg/blob/main/proposals/0020-distributed-actor-cluster.md&quot;&gt;Distributed Actors Cluster implementation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/swift-server/sswg/blob/main/proposals/0021-swift-cassandra-client.md&quot;&gt;Swift Cassandra client&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;continuing-the-concurrency-journey&quot;&gt;Continuing the concurrency journey&lt;/h3&gt;
&lt;p&gt;We are happy to see that the adoption of Swift Concurrency in the ecosystem has progressed significantly. All libraries in the SSWG incubation process have adopted new &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;async&lt;/code&gt;/&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await&lt;/code&gt; APIs where applicable and are continuing to roll out &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Sendable&lt;/code&gt; support.&lt;/p&gt;
&lt;p&gt;We are also seeing a trend of new APIs using only Swift Concurrency, and new projects with internals written using Swift Concurrency, like the &lt;a href=&quot;https://github.com/swift-server/swift-kafka-gsoc&quot;&gt;Kafka client library&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Were also excited to see the introduction of &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0392-custom-actor-executors.md&quot;&gt;Custom Actor Executors&lt;/a&gt;. The introduction of Custom Actor Executors offers more control over the behavior of concurrent code, helps improve performance, and will enable us to bridge more code into Swift concurrency.&lt;/p&gt;
&lt;h3 id=&quot;expanding-the-tooling&quot;&gt;Expanding the tooling&lt;/h3&gt;
&lt;p&gt;Notable highlights in tooling include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;a href=&quot;https://marketplace.visualstudio.com/items?itemName=sswg.swift-lang&quot;&gt;Swift Extension for Visual Studio Code&lt;/a&gt; reached version 1.0.0 and added new features like Swift Package plugin integration, Test Coverage and Test Explorer support, and more.&lt;/li&gt;
&lt;li&gt;Swift Package plugins have seen adoption in many libraries, from formatters and linters, to code generators such as &lt;a href=&quot;https://github.com/apple/swift-protobuf/tree/main/Plugins/SwiftProtobufPlugin&quot;&gt;SwiftProtobuf&lt;/a&gt;, &lt;a href=&quot;https://github.com/grpc/grpc-swift/tree/main/Plugins/GRPCSwiftPlugin&quot;&gt;gRPC swift&lt;/a&gt;, &lt;a href=&quot;https://github.com/amzn/smoke-framework-application-generate/tree/main/Plugins&quot;&gt;Smoke&lt;/a&gt;, and &lt;a href=&quot;https://soto.codes/2022/12/build-plugin-experiments.html&quot;&gt;Soto&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/swift-server/swiftly&quot;&gt;Swiftly&lt;/a&gt; is now available to try out and provides a simple way to install Swift on Linux and switch between versions.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;improving-build-times&quot;&gt;Improving build times&lt;/h3&gt;
&lt;p&gt;There have been a number of improvements to build times for Swift projects, including compiler optimizations, new build systems, and package manager enhancements.&lt;/p&gt;
&lt;p&gt;Swift Crypto Extras continues to add new APIs that allow libraries to avoid vending their own copies of BoringSSL. This, combined with the new &lt;a href=&quot;https://www.swift.org/blog/swift-certificates-and-asn1/&quot;&gt;Swift Certificates and ASN.1 libraries&lt;/a&gt;, helps libraries like &lt;a href=&quot;https://github.com/swift-server/webauthn-swift&quot;&gt;WebAuthn Swift&lt;/a&gt; avoid including their own cryptography libraries and instead use these new packages and APIs. This avoids compiling the same code multiple times and provides a significant speed improvement during compilation.&lt;/p&gt;
&lt;p&gt;Additionally, SSWG member Gwynne &lt;a href=&quot;https://github.com/apple/swift/pull/64312&quot;&gt;merged a PR for Swift 5.9&lt;/a&gt; that offers a 90% improvement to link time and memory usage on Linux, which should greatly help when building Swift applications in constrained environments.&lt;/p&gt;
&lt;h3 id=&quot;increasing-adoption-of-server-side-swift&quot;&gt;Increasing adoption of server-side Swift&lt;/h3&gt;
&lt;p&gt;The SSWG has continued to work with the community to increase adoption of Swift on the server:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The SSWG Guides and incubation processes have been migrated to &lt;a href=&quot;http://Swift.org&quot;&gt;Swift.org&lt;/a&gt; to make them more discoverable.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://swiftpackageindex.com/swift-server/async-http-client/documentation/asynchttpclient&quot;&gt;Many&lt;/a&gt; &lt;a href=&quot;https://swiftpackageindex.com/swift-server/RediStack/documentation/redistack&quot;&gt;of&lt;/a&gt; &lt;a href=&quot;https://swiftpackageindex.com/apple/swift-nio/documentation/nio&quot;&gt;the&lt;/a&gt; &lt;a href=&quot;https://swiftpackageindex.com/apple/swift-log/documentation/logging&quot;&gt;Swift&lt;/a&gt; &lt;a href=&quot;https://swiftpackageindex.com/apple/swift-metrics/documentation/coremetrics&quot;&gt;server&lt;/a&gt; &lt;a href=&quot;https://swiftpackageindex.com/swift-server/swift-aws-lambda-runtime/documentation/awslambdaruntime&quot;&gt;packages&lt;/a&gt; have adopted Swift Package Index documentation hosting to make discovering and using packages easier.&lt;/li&gt;
&lt;li&gt;The SSWG has created a survey to better understand the Swift on server community and help ensure efforts are applied to the right areas.&lt;/li&gt;
&lt;li&gt;We are observing an increase in the number of conference talks focused on production success stories and technical deep dives, reflecting a maturity in adoption and recognition of Swift on server.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;goals-for-2023&quot;&gt;Goals for 2023&lt;/h2&gt;
&lt;p&gt;The SSWG believes 2023 is turning out to be another exciting year for Swift on the server, with a continued focus on the following goals:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Continued focus on growing the ecosystem&lt;/li&gt;
&lt;li&gt;Adoption of structured concurrency&lt;/li&gt;
&lt;li&gt;Expand the documentation and guides&lt;/li&gt;
&lt;li&gt;Improve tooling&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;continued-focus-on-growing-the-ecosystem-1&quot;&gt;Continued focus on growing the ecosystem&lt;/h3&gt;
&lt;p&gt;In addition to supporting existing libraries, there are a number of areas of focus for this year:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a Swift-native Memcached client&lt;/li&gt;
&lt;li&gt;a common connection pool library to make it easy to adopt connection pooling&lt;/li&gt;
&lt;li&gt;a shared middleware implementation for use in web frameworks like Smoke, Hummingbird, and Vapor&lt;/li&gt;
&lt;li&gt;Encouraging adoption of distributing tracing to round out the &lt;a href=&quot;https://swiftpackageindex.com/apple/swift-distributed-tracing/1.0.1/documentation/tracing&quot;&gt;observability story&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Better showcases of Swift on server deployments and success stories&lt;/li&gt;
&lt;li&gt;Better visibility of Swift as a server language&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;adoption-of-structured-concurrency&quot;&gt;Adoption of structured concurrency&lt;/h3&gt;
&lt;p&gt;The SSWG believe that structured concurrency is a key feature that will make Swift on server stand out and provide a clear benefit to the ecosystem.&lt;/p&gt;
&lt;p&gt;Some plans for this year include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Produce an adoption guide for structured concurrency covering best practices around &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Sendable&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;async&lt;/code&gt;/&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TaskGroup&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Task&lt;/code&gt; APIs.&lt;/li&gt;
&lt;li&gt;Apply concurrency best practices to core ecosystem libraries such as &lt;a href=&quot;https://github.com/swift-server/swift-service-lifecycle&quot;&gt;swift-service-lifecycle&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;expand-the-documentation-and-guides&quot;&gt;Expand the documentation and guides&lt;/h3&gt;
&lt;p&gt;Documentation can always be improved and the SSWG will continue to expand our guides and usage documentation for the ecosystem.&lt;/p&gt;
&lt;p&gt;The SSWG are working with the Swift Website Workgroup to add guides for those new to Swift on the server as well as ensure that the existing guides can be easily found.&lt;/p&gt;
&lt;p&gt;The SSWG also plan to expand the documentation in key areas like security and deployment, covering topics like GitHubs Dependabot and AWSs Swift support in their CDK.&lt;/p&gt;
&lt;p&gt;Some of the upcoming design changes to &lt;a href=&quot;https://www.swift.org&quot;&gt;Swift.org&lt;/a&gt; will help place Swift on server documentation in a more prominent position to increase visibility.&lt;/p&gt;
&lt;h3 id=&quot;improve-tooling&quot;&gt;Improve tooling&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/swift-server/swiftly&quot;&gt;Swiftly&lt;/a&gt; is growing in popularity on Linux for managing multiple toolchains, and the SSWG would like to port it to Windows and macOS as well.&lt;/p&gt;
&lt;p&gt;There are a number of other tooling enhancements being explored, including:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Adding support for Swift Package Manager to GitHubs dependabot&lt;/li&gt;
&lt;li&gt;Investigating Canonicals Chiseled Containers to see if we can provide Swift containers with a very small footprint and a hardened security profile&lt;/li&gt;
&lt;li&gt;Investigating what we can do with Swift Package plugins to improve the deployment experience of Swift on server&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;new-sswg-members&quot;&gt;New SSWG Members&lt;/h2&gt;
&lt;p&gt;The SSWG is happy to welcome four new members:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Dave Moser - Dave joined the SSWG in May. Dave is part of the solution architecture team driving Swift on AWS, and has been involved with the Swift on server efforts for the last couple of years.&lt;/li&gt;
&lt;li&gt;Jimmy McDermott - Jimmy also joined the SSWG in May and represents Transeo. Jimmy has been involved with Swift on server since Vapors early days and is the CTO of Transeo, where he and his team use Vapor to scale services to millions of users.&lt;/li&gt;
&lt;li&gt;Franz Busch - Franz officially joined the SSWG on October 23rd and works on the SwiftNIO team at Apple.&lt;/li&gt;
&lt;li&gt;Joannis Orlandos - Joannis joined the SSWG at the start of this year. Joannis was a core contributor to Vapor and maintains a number of libraries in the ecosystem including &lt;a href=&quot;https://github.com/orlandos-nl/MongoKitten&quot;&gt;MongoKitten&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Franz takes over from Fabian Fett who has completed a two year stint on the SSWG. Dave takes over from Todd Varland who also completed a long stint on the SSWG. Kaitlin Mahar has changed roles at MongoDB and also completed a number of years on the SSWG. We are extremely grateful for all theyve done in their time on the SSWG and thank them for their hard work!&lt;/p&gt;
&lt;h2 id=&quot;going-forward&quot;&gt;Going Forward&lt;/h2&gt;
&lt;p&gt;If you have any ideas to share with the SSWG or want to pitch a library to the SSWG Incubation Process, please get in touch with us, either &lt;a href=&quot;https://forums.swift.org/c/server/43&quot;&gt;via the forums&lt;/a&gt; or through Slack.&lt;/p&gt;
</content>
</entry>
<entry>
<title>Introducing Swift HTTP Types</title>
<author>
<name>Swift.org</name>
</author>
<link href="https://swift.org/blog/introducing-swift-http-types/"/>
<updated>2023-07-10T06:00:00-04:00</updated>
<id>https://swift.org/blog/introducing-swift-http-types/</id>
<content type="html">&lt;p&gt;Were excited to announce a new open source package called &lt;a href=&quot;https://github.com/apple/swift-http-types&quot;&gt;Swift HTTP Types&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Building upon insights from Swift on server, app developers, and the broader Swift community, Swift HTTP Types is designed to provide a shared set of currency types for client/server HTTP operations in Swift.&lt;/p&gt;
&lt;h2 id=&quot;http-in-swift&quot;&gt;HTTP in Swift&lt;/h2&gt;
&lt;p&gt;Networking in Swift is ubiquitous for many use cases today, spanning clients, servers, intermediaries, and many other participants across the internet and other networks. HTTP is among the most popular networking technologies, powering daily experiences across the world.&lt;/p&gt;
&lt;p&gt;On Apple platforms, the system HTTP implementation is exposed via the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;URLSession&lt;/code&gt; API in the Foundation framework. For Swift on server projects, the recommended HTTP stack is implemented in &lt;a href=&quot;https://github.com/apple/swift-nio&quot;&gt;SwiftNIO&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;To provide the best possible experience for using HTTP in Swift, shared currency types, useful across many projects, are essential.&lt;/p&gt;
&lt;h2 id=&quot;swift-http-types&quot;&gt;Swift HTTP Types&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-http-types&quot;&gt;Swift HTTP Types&lt;/a&gt; provides a common representation of the core building blocks of HTTP messages.&lt;/p&gt;
&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;HTTPRequest&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;HTTPResponse&lt;/code&gt; represent HTTP messages for both client and server use cases. By adopting them across multiple projects, more code can be shared between clients and servers, eliminating the cost of converting between types when working with multiple frameworks.&lt;/p&gt;
&lt;p&gt;These types are built Swift-first to represent every valid HTTP message. Their representations are focused on modern HTTP versions like HTTP/3 and HTTP/2, while also retaining compatibility with HTTP/1.1.&lt;/p&gt;
&lt;p&gt;As the package matures, our goal is to replace SwiftNIOs &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;HTTPRequestHead&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;HTTPResponseHead&lt;/code&gt; as well as the HTTP message details of Foundations &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;URLRequest&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;URLResponse&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The new currency types are designed to be suitable for use in any HTTP scenario and are not tied to any existing framework, eliminating the need for duplicate HTTP abstractions.&lt;/p&gt;
&lt;h2 id=&quot;example-usage&quot;&gt;Example Usage&lt;/h2&gt;
&lt;p&gt;The API is designed to offer ergonomic ways to perform the most common HTTP operations, while scaling cleanly to represent advanced use cases.&lt;/p&gt;
&lt;p&gt;At their core, HTTP requests are comprised of a method, a scheme, an authority, and a path:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;request&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;HTTPRequest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;scheme&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;https&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;authority&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;www.example.com&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;/&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;We can also create the same request from a Foundation URL:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;request&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;HTTPRequest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;URL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;https://www.example.com/&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;We can change the method, or other properties, after the fact:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;method&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;post&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;/upload&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Creating a response is similarly straightforward:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;HTTPResponse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ok&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;We can access and modify header fields using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;headerFields&lt;/code&gt; property:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;headerFields&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;userAgent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;MyApp/1.0&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Common header fields are built-in, and we can easily provide extensions for custom header fields and values, so we can use the same convenient syntax in our business logic:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;extension&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;HTTPField&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Name&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;myCustomHeader&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;My-Custom-Header&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;headerFields&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;myCustomHeader&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;custom-value&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;We can directly set the value of the header field, including an array of values:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;headerFields&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;raw&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;acceptLanguage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;en-US&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;zh-Hans-CN&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Accessing header fields is much the same, and we can use system-defined fields or our own extensions:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;headerFields&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;userAgent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// &quot;MyApp/1.0&quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;headerFields&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;myCustomHeader&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// &quot;custom-value&quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;headerFields&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;acceptLanguage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// &quot;en-US, zh-Hans-CN&quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;headerFields&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;raw&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;acceptLanguage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// [&quot;en-US&quot;, &quot;zh-Hans-CN&quot;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h3 id=&quot;integrating-with-foundation&quot;&gt;Integrating with Foundation&lt;/h3&gt;
&lt;p&gt;Using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;URLSession&lt;/code&gt;, we can easily create a new &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;HTTPRequest&lt;/code&gt; to send a POST request to “www.example.com”. Setting a custom &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;User-Agent&lt;/code&gt; header field value on this request is intuitive and integrates with the type system to offer auto-completions:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;request&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;HTTPRequest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;URL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;https://www.example.com/upload&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;headerFields&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;userAgent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;MyApp/1.0&quot;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;responseBody&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;URLSession&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shared&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;upload&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;requestBody&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;guard&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;status&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;created&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Handle error&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h3 id=&quot;integrating-with-swiftnio&quot;&gt;Integrating with SwiftNIO&lt;/h3&gt;
&lt;p&gt;SwiftNIO integration will be available in the &lt;a href=&quot;https://github.com/apple/swift-nio-extras&quot;&gt;swift-nio-extras&lt;/a&gt; package when this package becomes stable. To configure a NIO channel handler for use with the new HTTP types, we can add &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;HTTP2FramePayloadToHTTPServerCodec&lt;/code&gt; before our other channel handlers:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;NIOTSListenerBootstrap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;group&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;NIOTSEventLoopGroup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;childChannelInitializer&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;channel&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;channel&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;configureHTTP2Pipeline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;mode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;server&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;channel&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;channel&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pipeline&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;addHandlers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;HTTP2FramePayloadToHTTPServerCodec&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;ExampleChannelHandler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;map&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;tlsOptions&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tlsOptions&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Our example channel implementation processes both &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;HTTPRequest&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;HTTPResponse&lt;/code&gt; types:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ExampleChannelHandler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ChannelDuplexHandler&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;typealias&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;InboundIn&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;HTTPTypeServerRequestPart&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;typealias&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;OutboundOut&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;HTTPTypeServerResponsePart&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;channelRead&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ChannelHandlerContext&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;NIOAny&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;switch&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;unwrapInboundIn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Handle request headers&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Handle request body&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;trailers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Handle complete request&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;HTTPResponse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ok&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;wrapOutboundOut&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)),&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;promise&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;writeAndFlush&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;wrapOutboundOut&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)),&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;promise&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h2 id=&quot;request-and-response-body&quot;&gt;Request and Response Body&lt;/h2&gt;
&lt;p&gt;HTTP request and response bodies are not currently part of this package.&lt;/p&gt;
&lt;p&gt;Please continue to use existing the mechanisms: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Data&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;InputStream&lt;/code&gt; for Foundation and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ByteBuffer&lt;/code&gt; for SwiftNIO.&lt;/p&gt;
&lt;p&gt;We are interested in exploring proposals with the community to provide body handling in the future.&lt;/p&gt;
&lt;h2 id=&quot;get-involved&quot;&gt;Get Involved&lt;/h2&gt;
&lt;p&gt;The experience and expertise from this community is invaluable in creating the building blocks for a great HTTP experience in Swift.&lt;/p&gt;
&lt;p&gt;The version of Swift HTTP Types were releasing today is a starting point for feedback and discussion with the community.&lt;/p&gt;
&lt;p&gt;You can get started by:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Trying out the &lt;a href=&quot;https://github.com/apple/swift-http-types&quot;&gt;swift-http-types package&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Participating in discussions with the &lt;a href=&quot;https://forums.swift.org/tag/http&quot;&gt;#http tag on the Swift forums&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Opening &lt;a href=&quot;https://github.com/apple/swift-http-types/issues&quot;&gt;issues and contributing&lt;/a&gt; for any problems you find&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Were looking forward to exploring the future of HTTP in Swift together.&lt;/p&gt;
</content>
</entry>
<entry>
<title>Introducing Swift OpenAPI Generator</title>
<author>
<name>Swift.org</name>
</author>
<link href="https://swift.org/blog/introducing-swift-openapi-generator/"/>
<updated>2023-06-12T07:00:00-04:00</updated>
<id>https://swift.org/blog/introducing-swift-openapi-generator/</id>
<content type="html">&lt;p&gt;Were excited to announce a set of open source libraries designed to help both client and server developers streamline their workflow around HTTP communication using the industrystandard OpenAPI specification.&lt;/p&gt;
&lt;h2 id=&quot;what-is-openapi&quot;&gt;What is OpenAPI?&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://www.openapis.org/&quot;&gt;OpenAPI&lt;/a&gt; is a specification for documenting HTTP services. An OpenAPI document is written in either YAML or JSON, and can be read by tools to help automate workflows, such as generating the necessary code to send and receive HTTP requests.&lt;/p&gt;
&lt;p&gt;By serving as the source of truth, OpenAPI solves the problem of communicating the API contract between a service and its clients. It removes the need to read potentially inaccurate, handwritten documentation, or to observe network traffic, just to figure out the correct way to call a service. It helps you avoid this timeconsuming, repetitive, and errorprone work not just when adopting a service for the first time, but also as the service continues to evolve.&lt;/p&gt;
&lt;p&gt;To see OpenAPI and its benefits in action, lets consider a simple service called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GreetingService&lt;/code&gt; that:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;listens for an HTTP &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GET&lt;/code&gt; request at the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/greet&lt;/code&gt; endpoint&lt;/li&gt;
&lt;li&gt;with an optional query parameter called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;name&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;and returns the HTTP status code &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;200 OK&lt;/code&gt;, alongside a JSON body, which might look like this:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;language-json highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;message&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Hello, Jane!&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Such a service can be described using the OpenAPI document below:&lt;/p&gt;
&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;na&quot;&gt;openapi&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;3.0.3&apos;&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;GreetingService&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;version&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;1.0.0&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;servers&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;http://localhost:8080&quot;&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Localhost&quot;&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;paths&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;/greet&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;operationId&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;getGreeting&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;parameters&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;name&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;query&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;schema&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;string&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;responses&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;200&apos;&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;A success response with a greeting.&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;application/json&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;schema&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;$ref&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;#/components/schemas/Greeting&quot;&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;components&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;schemas&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;Greeting&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;properties&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;string&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;required&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;message&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;This simple OpenAPI document defines the structure of the HTTP request and response, including the HTTP method, URL path and query parameters, HTTP status code and content type, and uses &lt;a href=&quot;https://json-schema.org&quot;&gt;JSON Schema&lt;/a&gt; to describe the structure of the response body.&lt;/p&gt;
&lt;p&gt;OpenAPI also allows defining additional details not shown above, such as query items and request bodies (see &lt;a href=&quot;https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md&quot;&gt;OpenAPI 3.0.3 specification&lt;/a&gt; for more details).&lt;/p&gt;
&lt;h2 id=&quot;swift-openapi-generator&quot;&gt;Swift OpenAPI Generator&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-openapi-generator&quot;&gt;Swift OpenAPI Generator&lt;/a&gt; is a SwiftPM plugin that takes an OpenAPI document and generates either the client code to perform HTTP calls or the server code to handle those calls. The generated code translates between a typesafe representation of each operations input and output, and the underlying HTTP request and response.&lt;/p&gt;
&lt;p&gt;So whether developing an app that serves as a client of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GreetingService&lt;/code&gt; or implementing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GreetingService&lt;/code&gt; itself, Swift OpenAPI Generator generates the networking code for you, allowing you to focus on the core logic.&lt;/p&gt;
&lt;h3 id=&quot;adopting-the-plugin&quot;&gt;Adopting the Plugin&lt;/h3&gt;
&lt;p&gt;To use the Swift OpenAPI Generator plugin, you need to:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Add package dependencies for:
&lt;ul&gt;
&lt;li&gt;The package plugin (&lt;a href=&quot;https://github.com/apple/swift-openapi-generator&quot;&gt;swift-openapi-generator&lt;/a&gt;), which performs code generation at build time&lt;/li&gt;
&lt;li&gt;The runtime library (&lt;a href=&quot;https://github.com/apple/swift-openapi-runtime&quot;&gt;swift-openapi-runtime&lt;/a&gt;), which contains protocol definitions used by the generated code and extension libraries&lt;/li&gt;
&lt;li&gt;A transport implementation, which allows plugging in your chosen HTTP client library or server framework&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Enable the package plugin on your target and add target dependencies for the runtime and transport libraries.&lt;/li&gt;
&lt;li&gt;Add the following two files to your target:
&lt;ul&gt;
&lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;openapi.yaml&lt;/code&gt;, the OpenAPI document describing your API.&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;openapi-generator-config.yaml&lt;/code&gt;, a configuration file for the plugin, which controls whether to generate client or server code.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote&gt;
&lt;p&gt;Tip: For more information about adopting the plugin in your Swift package or Xcode project, check out our step-by-step &lt;a href=&quot;https://swiftpackageindex.com/apple/swift-openapi-generator/tutorials/swift-openapi-generator&quot;&gt;tutorials&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;using-a-generated-api-client&quot;&gt;Using a Generated API Client&lt;/h3&gt;
&lt;p&gt;When developing a client, such as an iOS app, you are provided with two generated types:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;APIProtocol&lt;/code&gt;, a Swift protocol that contains one method per OpenAPI operation.
&lt;ul&gt;
&lt;li&gt;In the case of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GreetingService&lt;/code&gt;, it contains a single method called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getGreeting&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Client&lt;/code&gt;, a Swift struct that implements &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;APIProtocol&lt;/code&gt;, which is used to make API calls to the server.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Below is example code to instantiate the client and fetch a greeting from the server:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;OpenAPIRuntime&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;OpenAPIURLSession&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Instantiate your chosen transport library.&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;transport&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ClientTransport&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;URLSessionTransport&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Create a client to connect to a server URL documented in the OpenAPI document.&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;serverURL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Servers&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;server1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;transport&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;transport&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Make the HTTP call using a type-safe method.&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;getGreeting&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;query&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Jane&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Switch over the HTTP response status code.&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;switch&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ok&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;okResponse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Switch over the response content type.&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;switch&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;okResponse&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;body&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;greeting&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Print the greeting message.&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;👋 &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;greeting&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;undocumented&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;statusCode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;statusCode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Handle HTTP response status codes not documented in the OpenAPI document.&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;🥺 undocumented response: &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;statusCode&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;blockquote&gt;
&lt;p&gt;Note: While the sample code above uses the &lt;a href=&quot;https://github.com/apple/swift-openapi-urlsession&quot;&gt;URLSession-based client transport&lt;/a&gt;, there are other client transport implementations, or you can create your own.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;using-generated-api-server-stubs&quot;&gt;Using Generated API Server Stubs&lt;/h3&gt;
&lt;p&gt;When developing a server, you get two generated types for use in your code:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;APIProtocol&lt;/code&gt;, a protocol that contains one method per OpenAPI operation, the same as in the client example above.&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;APIProtocol.registerHandlers&lt;/code&gt;, a method on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;APIProtocol&lt;/code&gt; that registers one handler per OpenAPI operation, which calls the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getGreeting&lt;/code&gt; method that you implement.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Below is example code to implement a simple handler and use it to start the server:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;OpenAPIRuntime&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;OpenAPIVapor&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Vapor&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// A server implementation of the GreetingService API.&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Handler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;APIProtocol&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getGreeting&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Operations&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getGreeting&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Input&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;throws&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Operations&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getGreeting&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Output&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;message&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Hello, &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;query&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;??&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Stranger&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;!&quot;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;greeting&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Components&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Schemas&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Greeting&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ok&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;greeting&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Create the Vapor app.&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;app&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Vapor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Application&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Create the transport.&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;transport&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ServerTransport&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;VaporTransport&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;routesBuilder&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Create the request handler, which contains your server logic.&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;handler&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Handler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Register the generated routes on the transport.&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;handler&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;registerHandlers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;transport&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Start the server.&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;blockquote&gt;
&lt;p&gt;Note: While the sample code above uses the &lt;a href=&quot;https://github.com/swift-server/swift-openapi-vapor&quot;&gt;Vapor-based server transport&lt;/a&gt;, there are other server transport implementations, or you can create your own.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;transport-implementations&quot;&gt;Transport Implementations&lt;/h2&gt;
&lt;p&gt;Swift OpenAPI Generator works with any HTTP client or server library by abstracting the HTTP library interface in the protocols &lt;a href=&quot;https://swiftpackageindex.com/apple/swift-openapi-runtime/documentation/openapiruntime/clienttransport&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ClientTransport&lt;/code&gt;&lt;/a&gt; and &lt;a href=&quot;https://swiftpackageindex.com/apple/swift-openapi-runtime/documentation/openapiruntime/servertransport&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ServerTransport&lt;/code&gt;&lt;/a&gt;. Similar to projects like &lt;a href=&quot;https://github.com/apple/swift-log#selecting-a-logging-backend-implementation-applications-only&quot;&gt;swift-log&lt;/a&gt;, Swift OpenAPI Generator uses the &lt;em&gt;API package&lt;/em&gt; approach for greater extensibility.&lt;/p&gt;
&lt;p&gt;Below are some examples of existing transport implementations that you can try out today:&lt;/p&gt;
&lt;h3 id=&quot;client-transport-implementations&quot;&gt;Client Transport Implementations&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-openapi-urlsession&quot;&gt;apple/swift-openapi-urlsession&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/swift-server/swift-openapi-async-http-client&quot;&gt;swift-server/swift-openapi-async-http-client&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;server-transport-implementations&quot;&gt;Server Transport Implementations&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/swift-server/swift-openapi-vapor&quot;&gt;swift-server/swift-openapi-vapor&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/swift-server/swift-openapi-hummingbird&quot;&gt;swift-server/swift-openapi-hummingbird&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;whats-next&quot;&gt;Whats Next&lt;/h2&gt;
&lt;p&gt;The project is being open sourced early in its development so the community can provide feedback and help us arrive at a stable 1.0 release.&lt;/p&gt;
&lt;p&gt;The initial focus was on implementing features defined by &lt;a href=&quot;https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md&quot;&gt;version 3.0.3&lt;/a&gt; of the OpenAPI specification, with ongoing work toward supporting &lt;a href=&quot;https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md&quot;&gt;OpenAPI 3.1&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;While Swift OpenAPI Generator supports most of the commonly used features of OpenAPI, there are still several features left to implement, and progress is tracked publicly using GitHub &lt;a href=&quot;https://github.com/apple/swift-openapi-generator/issues&quot;&gt;issues&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;get-involved&quot;&gt;Get Involved&lt;/h2&gt;
&lt;p&gt;Check out the repositories, open issues, pull requests, and let us know what you think in the Swift &lt;a href=&quot;https://forums.swift.org/c/server&quot;&gt;forums&lt;/a&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://developer.apple.com/wwdc23/10171&quot;&gt;Meet Swift OpenAPI Generator&lt;/a&gt; at WWDC23&lt;/li&gt;
&lt;li&gt;Swift OpenAPI Generator: &lt;a href=&quot;https://github.com/apple/swift-openapi-generator&quot;&gt;https://github.com/apple/swift-openapi-generator&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Swift OpenAPI Runtime: &lt;a href=&quot;https://github.com/apple/swift-openapi-runtime&quot;&gt;https://github.com/apple/swift-openapi-runtime&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Were excited about what Swift OpenAPI Generator can do for the Swift community by reducing the amount of time it takes to connect to an HTTP service or implement one yourself.&lt;/p&gt;
</content>
</entry>
<entry>
<title>Using Upcoming Feature Flags</title>
<author>
<name>Swift.org</name>
</author>
<link href="https://swift.org/blog/using-upcoming-feature-flags/"/>
<updated>2023-05-30T06:00:00-04:00</updated>
<id>https://swift.org/blog/using-upcoming-feature-flags/</id>
<content type="html">&lt;p&gt;Beginning in Swift 5.8 you can flexibly adopt upcoming Swift features using a new compiler flag and compilation condition. This post describes the problem upcoming feature flags solve, their benefits, and how to get started using them in your projects.&lt;/p&gt;
&lt;h2 id=&quot;source-breaking-changes&quot;&gt;Source-Breaking Changes&lt;/h2&gt;
&lt;p&gt;Each new release of Swift adds features and capabilities. These changes go through the &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/process.md&quot;&gt;Swift Evolution process&lt;/a&gt; where they are proposed, discussed by the community, and accepted.&lt;/p&gt;
&lt;p&gt;One important consideration for all changes to Swift is &lt;em&gt;source compatibility&lt;/em&gt;. To be source compatible, existing Swift code must continue to compile and behave as expected with new versions of the compiler.&lt;/p&gt;
&lt;p&gt;To help meet this strong goal, the Swift project maintains an extensive &lt;a href=&quot;/documentation/source-compatibility/&quot;&gt;source compatibility test suite&lt;/a&gt;. Proposed changes are tested to ensure they do not introduce source-breaking changes. In addition, each evolution proposal includes a discussion of source compatibility.&lt;/p&gt;
&lt;p&gt;On rare occasions, a proposed change that breaks source compatibility is considered important enough to be accepted. These source-breaking changes are not introduced immediately, but wait until the next major version of Swift.&lt;/p&gt;
&lt;h2 id=&quot;an-example-regex-literals&quot;&gt;An Example: Regex Literals&lt;/h2&gt;
&lt;p&gt;One example of a source-breaking change is the syntax for Regex literals introduced in Swift 5.7.&lt;/p&gt;
&lt;p&gt;The desired literal syntax is to enclose the regex pattern in forward slashes, which is the convention for regular expressions in many different tools and languages:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;regex&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;sr&quot;&gt;/[a-zA-Z_][0-9a-zA-Z_]*/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;However, there are cases where this new syntax would break existing code, as detailed in &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0354-regex-literals.md#source-compatibility&quot;&gt;the SE-0354 proposal&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Even though the source incompatibility would not affect many projects and is not likely to be a difficult fix in affected projects, it is still a breaking change.&lt;/p&gt;
&lt;p&gt;Therefore, in Swift 5.7, regex literals only support the extended literal delimiters:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;regex&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;sr&quot;&gt;#/[a-zA-Z_][0-9a-zA-Z_]*/#&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;The source breaking change does not come into effect until the next major language version — Swift 6.&lt;/p&gt;
&lt;p&gt;However, it would be beneficial for developers to be able to opt into using the bare slash syntax for Regex literals now, rather than wait until Swift 6.&lt;/p&gt;
&lt;p&gt;To allow this, when Swift 5.7 was introduced, a new compiler flag &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-enable-bare-slash-regex&lt;/code&gt; was added. For any target with this flag set, the Swift 6 syntax is accepted.&lt;/p&gt;
&lt;p&gt;SDKs that shipped with Xcode 14 have this flag set by default, so you may already be using this syntax.&lt;/p&gt;
&lt;h2 id=&quot;a-generalized-solution&quot;&gt;A Generalized Solution&lt;/h2&gt;
&lt;p&gt;The idea of being able to adopt upcoming changes sooner rather than later is a good one. However, adding an ever-increasing number of separate compiler flags for each upcoming feature does not scale well.&lt;/p&gt;
&lt;p&gt;To address this, Swift evolution proposal &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0362-piecemeal-future-features.md&quot;&gt;SE-0362&lt;/a&gt;, implemented in Swift 5.8, details a generalized mechanism for enabling upcoming features.&lt;/p&gt;
&lt;p&gt;Instead of creating a different compiler flag for each upcoming feature, the compiler gains one new flag that is followed by the name of the feature to be enabled:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; -enable-upcoming-feature SomeUpcomingFeature
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;For example, to enable the upcoming Regex literal syntax you would use:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; -enable-upcoming-feature BareRegexLiteralSyntax
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;In Swift Package Manager manifests you specify these using a new &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SwiftSetting&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;enableUpcomingFeature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;BareSlashRegexLiterals&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h3 id=&quot;checking-for-features-in-code&quot;&gt;Checking For Features In Code&lt;/h3&gt;
&lt;p&gt;SE-0362 also introduces a new &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hasFeature()&lt;/code&gt; compilation condition that checks whether a feature is enabled. This allows you to write code that uses a feature if present or uses alternate code if not present.&lt;/p&gt;
&lt;p&gt;You specify which feature by using its upcoming feature flag as an argument to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hasFeature()&lt;/code&gt;, as shown in the example below.&lt;/p&gt;
&lt;p&gt;Note that since &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hasFeature()&lt;/code&gt; was introduced with the Swift 5.8 compiler, earlier versions do not recognize it. You may need to check the compiler version when using it.&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;#if compiler(&amp;gt;=5.8)&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#if hasFeature(BareSlashRegexLiterals)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;regex&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;sr&quot;&gt;/.../&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#else&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;regex&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;sr&quot;&gt;#/.../#&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#endif&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#else&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;regex&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;NSRegularExpression&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;pattern&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;...&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#endif&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;The section &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0362-piecemeal-future-features.md#feature-detection-in-source-code&quot;&gt;Feature detection in source code&lt;/a&gt; in SE-0362 discusses the use of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hasFeature()&lt;/code&gt; in detail.&lt;/p&gt;
&lt;h2 id=&quot;benefits-of-enabling-upcoming-features&quot;&gt;Benefits Of Enabling Upcoming Features&lt;/h2&gt;
&lt;p&gt;There are two significant benefits to enabling upcoming features in your code.&lt;/p&gt;
&lt;p&gt;First, youll find out immediately if your code will require changes. This lets you discover the scope of any work needed and gives you the flexibility to update your code now or when it best fits your schedule.&lt;/p&gt;
&lt;p&gt;Second, you can start using the upcoming features right away. All new code you write incorporates these changes, easing your eventual move to the next major language version. Youll also begin building muscle memory and experience with the upcoming syntax and behavior.&lt;/p&gt;
&lt;h2 id=&quot;how-to-enable-upcoming-features&quot;&gt;How To Enable Upcoming Features&lt;/h2&gt;
&lt;p&gt;You enable an upcoming feature by setting the compiler flag for a given target.&lt;/p&gt;
&lt;p&gt;To enable multiple features, use the compiler flag multiple times, once per enabled feature.&lt;/p&gt;
&lt;p&gt;This allows you to adopt features in a very flexible manner, target by target, feature by feature.&lt;/p&gt;
&lt;h3 id=&quot;in-xcode&quot;&gt;In Xcode&lt;/h3&gt;
&lt;p&gt;For Xcode projects, add the compiler flags to the Other Swift Flags build setting:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;In the project navigator, select the project&lt;/li&gt;
&lt;li&gt;In the project editor, select the desired target or the project itself&lt;/li&gt;
&lt;li&gt;Select the Build Settings tab&lt;/li&gt;
&lt;li&gt;Make sure the All scope button is selected&lt;/li&gt;
&lt;li&gt;Search for swift flags to find the Other Swift Flags build setting&lt;/li&gt;
&lt;li&gt;Double-click to add one or more &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-enable-upcoming-feature&lt;/code&gt; flags to the setting&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The screenshot below shows three upcoming features being enabled:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/upcoming-feature-flags-blog/upcoming-feature-flags-xcode.png&quot; alt=&quot;Screen capture of Xcode project editor with app target, Build Settings tab, and All scope bar button selected. Displaying the Other Swift Flags build setting and a popover showing the list of flags -enable-upcoming-feature, ConciseMagicFile, -enable-upcoming-feature, ExistentialAny, -enable-upcoming-feature, BareSlashRegexLiterals&quot; width=&quot;680&quot; /&gt;&lt;/p&gt;
&lt;p&gt;If your project uses &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;xcconfig&lt;/code&gt; configuration files, you can improve the readability of multiple settings by using a backslash to have the build setting span multiple lines:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;OTHER_SWIFT_FLAGS&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;inherited&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;enable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;upcoming&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;feature&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ConciseMagicFile&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;enable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;upcoming&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;feature&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;BareSlashRegexLiterals&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;enable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;upcoming&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;feature&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ExistentialAny&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h3 id=&quot;in-swiftpm-packages&quot;&gt;In SwiftPM Packages&lt;/h3&gt;
&lt;p&gt;For a Swift package, enable upcoming features for a target in its &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SwiftSetting&lt;/code&gt; array in the package manifest:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;MyTarget&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;dependencies&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:[&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fancyLibrary&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;swiftSettings&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;enableUpcomingFeature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;ConciseMagicFile&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;enableUpcomingFeature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;BareSlashRegexLiterals&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;enableUpcomingFeature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;ExistentialAny&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;You will also need to update the tools version specified in the manifest to 5.8 or later:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// swift-tools-version: 5.8&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h2 id=&quot;finding-upcoming-feature-flags&quot;&gt;Finding Upcoming Feature Flags&lt;/h2&gt;
&lt;p&gt;Use the &lt;a href=&quot;/swift-evolution/&quot;&gt;Swift Evolution Dashboard&lt;/a&gt; to find upcoming feature flags:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Filter to see all proposals with an upcoming feature flag&lt;/li&gt;
&lt;li&gt;Search for upcoming feature flags by name&lt;/li&gt;
&lt;li&gt;View upcoming feature flags for proposals that define one&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Each dashboard entry links to full Swift Evolution proposal where the upcoming feature flag is defined. Details on the changes that the flag enables are in the body of the proposal, typically in the &lt;em&gt;Source Compatibility&lt;/em&gt; section.&lt;/p&gt;
&lt;p&gt;Its also important to note that most changes to Swift maintain source compatibility and therefore do not have an upcoming feature flag.&lt;/p&gt;
&lt;h2 id=&quot;upcoming-feature-flags-added-in-swift-58&quot;&gt;Upcoming Feature Flags Added In Swift 5.8&lt;/h2&gt;
&lt;p&gt;As of Swift 5.8, the current set of upcoming feature flags are:&lt;/p&gt;
&lt;h4 id=&quot;se-0274-concise-magic-file-names&quot;&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0274-magic-file.md&quot;&gt;SE-0274&lt;/a&gt;: Concise magic file names&lt;/h4&gt;
&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#file&lt;/code&gt; literal generates a string with the format &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;module-name&amp;gt;/&amp;lt;file-name&amp;gt;&lt;/code&gt; instead of the full file path.&lt;/p&gt;
&lt;p&gt;Upcoming Feature Flag: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ConciseMagicFile&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0274-magic-file.md#source-compatibility&quot;&gt;Read Full Details&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&quot;se-0286-forward-scan-matching-for-trailing-closures&quot;&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0286-forward-scan-trailing-closures.md&quot;&gt;SE-0286&lt;/a&gt;: Forward-scan matching for trailing closures&lt;/h4&gt;
&lt;p&gt;Some existing methods can be ambiguous or fail to type check when called using multiple trailing closures. In these cases, provide the closures as regular arguments.&lt;/p&gt;
&lt;p&gt;Upcoming Feature Flag: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ForwardTrailingClosures &lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0286-forward-scan-trailing-closures.md#mitigating-the-source-compatibility-impact-swift--6&quot;&gt;Read Full Details&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&quot;se-0335-introduce-existential-any&quot;&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md&quot;&gt;SE-0335&lt;/a&gt;: Introduce existential any&lt;/h4&gt;
&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;any&lt;/code&gt; keyword must be used when a protocol is used as an existential type.&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;@protocol&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Drawable&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;drawable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;any&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Drawable&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// Use of &apos;any&apos; keyword required&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Upcoming Feature Flag: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ExistentialAny &lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md#source-compatibility&quot;&gt;Read Full Details&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&quot;se-0354-regex-literals&quot;&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0354-regex-literals.md&quot;&gt;SE-0354&lt;/a&gt;: Regex literals&lt;/h4&gt;
&lt;p&gt;Allows Regex literals to use forward slash as the delimiter.&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;regex&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;sr&quot;&gt;/[a-zA-Z_][0-9a-zA-Z_]*/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Upcoming Feature Flag: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;BareSlashRegexLiterals &lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0354-regex-literals.md#source-compatibility&quot;&gt;Read Full Details&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;get-started-today&quot;&gt;Get Started Today&lt;/h2&gt;
&lt;p&gt;Enabling upcoming features gives you a flexible way to migrate your code to adopt changes coming in the next major release of Swift at your own pace, feature by feature, target by target.&lt;/p&gt;
&lt;p&gt;You can start looking into these features today in a low-risk way by creating a test branch of your project and enabling upcoming features one at a time, one target at a time.&lt;/p&gt;
&lt;p&gt;Of course, on a team, code migration of this sort needs to be planned and communicated.&lt;/p&gt;
&lt;p&gt;These new capabilities in Swift 5.8 give you and your team additional lead time and flexibility to investigate, plan, and schedule any changes needed to adopt upcoming features.&lt;/p&gt;
</content>
</entry>
<entry>
<title>Evolving the Swift Workgroups</title>
<author>
<name>Swift.org</name>
</author>
<link href="https://swift.org/blog/evolving-swift-project-workgroups/"/>
<updated>2023-05-18T06:30:00-04:00</updated>
<id>https://swift.org/blog/evolving-swift-project-workgroups/</id>
<content type="html">&lt;p&gt;Today, the Swift Core Team is announcing forward-looking changes to the structure of Swift, the work, and the people around it. These changes include new groups, names, organization, as well as inclusion as a first-class concept for each group:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;We are organizing all workgroups into two tiers — steering groups and workgroups.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;We are incorporating the core mission of Diversity in Swift in all workgroups.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;We are creating the Ecosystem Steering Group and Contributor Experience Workgroups to provide vital support for the growing Swift developer ecosystem and community.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Lets dive into the details.&lt;/p&gt;
&lt;h2 id=&quot;steering-groups-and-workgroups&quot;&gt;Steering Groups and Workgroups&lt;/h2&gt;
&lt;p&gt;Until today, the Swift project used “team” and “workgroup” interchangeably to describe groups working together on some community effort or area of responsibility.&lt;/p&gt;
&lt;p&gt;Aside from using “team” for the Core Team, we will consistently use the term &lt;strong&gt;group&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Each group will have a clear charter and focus. Groups can also have &lt;strong&gt;subgroups&lt;/strong&gt; that are smaller scoped units of focus under another group.&lt;/p&gt;
&lt;p&gt;There are two kinds of groups:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Steering groups&lt;/strong&gt; are responsible for the overall strategic direction in a broad area or a necessary process that affects the entire community.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Workgroups&lt;/strong&gt; represent functional areas of the project and drive work in a particular area. Subgroups of workgroups help further refine tasks and deliverables. Workgroups are long-term and focus on a specific domain. Various active contributors lead workgroups.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The purpose of workgroups is to provide structure to help support contributors in organizing and driving activity. However, workgroups are only one of the ways to organize and contribute to Swift. Most contributions and community activities begin and grow organically. Once an effort reaches sufficient momentum and size where it could benefit from support from the Swift project, forming a workgroup for that effort makes sense.&lt;/p&gt;
&lt;p&gt;Note that the &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/process.md&quot;&gt;evolution workgroups&lt;/a&gt; as described in the Swift Evolution process, can either be steering groups or workgroups. Evolution workgroups are groups that utilize or manage the Swift Evolution process in some way to achieve their core charter.&lt;/p&gt;
&lt;h3 id=&quot;adopting-the-groups-terminology&quot;&gt;Adopting the “Groups” Terminology&lt;/h3&gt;
&lt;p&gt;We are adjusting the names of the current groups and “teams” to match the new terminology.&lt;/p&gt;
&lt;p&gt;Steering groups:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;Language Workgroup&lt;/strong&gt; becomes the &lt;strong&gt;Language Steering Group&lt;/strong&gt;, and continues to use the Swift Evolution process to help drive the language forward. The groups membership will change over time as contributors are recognized for their active participation in helping shape the direction of the Swift language.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Workgroups:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The &lt;strong&gt;Server Workgroup&lt;/strong&gt;, often referred to as the “Swift on Server Workgroup,” promotes the use of Swift for developing and deploying server applications.
The workgroup has helped &lt;a href=&quot;/sswg/incubation-process.html&quot;&gt;incubate&lt;/a&gt; more than twenty critical server libraries, some of which the workgroup members developed together with the rest of the community. It also published in-depth guides for developing, deploying, and troubleshooting server applications written in Swift.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The &lt;strong&gt;Documentation Workgroup&lt;/strong&gt; helps guide the documentation experience for Swift. The workgroup shepherds the development of &lt;a href=&quot;https://github.com/apple/swift-docc&quot;&gt;Swift-DocC&lt;/a&gt; features that bring exciting ways to customize and enhance the experience of authored API documentation. The group also published a revamped version of &lt;em&gt;&lt;a href=&quot;https://docs.swift.org/swift-book/documentation/the-swift-programming-language/&quot;&gt;The Swift Programming Language&lt;/a&gt;&lt;/em&gt; book written using DocC and maintained by the open source community.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The &lt;strong&gt;Website Workgroup&lt;/strong&gt; helps guide the evolution on the &lt;a href=&quot;http://swift.org/&quot;&gt;Swift.org&lt;/a&gt; website. Since its inception, the website workgroup has helped review and integrate community-driven improvements to the website, including the introduction of server development guides in collaboration with the server workgroup, integration of the Swift Evolution dashboard, and numerous documentation and language fixes. The workgroup has also established a process for community-driven blog posts (initially piloted by the Diversity in Swift workgroup) designed to provide opportunities for community members to showcase their journey with Swift.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The &lt;strong&gt;C++ Interoperability Workgroup&lt;/strong&gt; works to build and advance the interoperability support between Swift and C++, prototyping and proposing changes to Swift that go through the Swift Evolution process.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Overseeing the steering and workgroups is the &lt;strong&gt;Swift Core Team&lt;/strong&gt;. We briefly considered adjusting its name to adopt the “group” terminology, but decided to retain its “team” name because it has been in use for so long and is widely recognized by the community. The Swift Core team, is a body that provides cohesion and strategic alignment across the Swift communitys various Groups and initiatives. The Project Lead appoints members of the Core Team to bring a mixture of experience, expertise, and leadership so the group may act as effective stewards for the Swift project and its community. The Core Teams membership will change over time, and the size and shape will evolve with the Swift projects needs. The Core Team does not make decisions by voting but by general consensus, with the Project Lead stepping in to resolve discussions.&lt;/p&gt;
&lt;h2 id=&quot;extending-diversity-in-swift&quot;&gt;Extending Diversity in Swift&lt;/h2&gt;
&lt;p&gt;The Diversity in Swift Workgroups mission is to identify pathways to contribute outside the main Swift codebase by creating intentional, concerted efforts to bring new voices to the community. Its achievements are lasting: we now have a community-written blog post process, mentoring programs, and specific community groups for developers to connect with others who have similar experiences and backgrounds, such as Women in Swift, Black in Swift, and Pride in Swift.&lt;/p&gt;
&lt;p&gt;Inclusion and diversity are fundamental values in the Swift project that need to be ingrained in the projects day-to-day operation.&lt;/p&gt;
&lt;p&gt;Today, Diversity in Swift is growing as a shared responsibility throughout the Swift project structure. Each group will designate an individual to serve in the new, rotating role of a Diversity in Swift champion. Diversity in Swift champions across all groups will work together to guide their respective groups to participate in initiatives such as the Swift Mentorship Program and form new initiatives. They will provide a feedback channel for members of the Swift community to discuss the topic of inclusion and diversity.&lt;/p&gt;
&lt;p&gt;The current members and initiatives of the Diversity in Swift Workgroup will be spread out among the other groups and incorporated into their respective charters. New groups formed in the future will be required to designate a Diversity in Swift champion and address how the workgroup will uphold our values of inclusion in the charter.&lt;/p&gt;
&lt;h2 id=&quot;announcing-new-groups&quot;&gt;Announcing New Groups&lt;/h2&gt;
&lt;p&gt;Over the coming weeks, the Swift project will add two new groups to provide support in areas of growing momentum in the Swift project. This overall picture of groups will look as follows:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/evolving-workgroups-blog/community-structure.png&quot; alt=&quot;Swift Workgroups Diagram&quot; /&gt;&lt;/p&gt;
&lt;h3 id=&quot;ecosystem-steering-group&quot;&gt;Ecosystem Steering Group&lt;/h3&gt;
&lt;p&gt;Notably, we will be creating a new &lt;strong&gt;Ecosystem Steering Group.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Successful programming languages have an extensive supporting system focused on developer experience and productivity through tooling, documentation, and other development resources.&lt;/p&gt;
&lt;p&gt;The new Ecosystem Steering Group will focus on growing that support structure for Swift. It will support the evolution of developer and documentation tooling, the Swift.org website, the package manager, and the package ecosystem. The steering group will also support the work to bring Swift to additional platforms and the tooling to make creating such ports easier. Finally, the group will support the growth of Swift in standard or industry-leading developer productivity tooling including cloud-based IDEs and continuous integration systems.&lt;/p&gt;
&lt;p&gt;A follow-up announcement will provide additional details on the charter of the Ecosystem Steering Group, its scope and responsibilities. With its charter formalized, the new steering group will form an additional set of workgroups to drive specific initiatives within its charter. The Core Team will choose the inaugural members of the Ecosystem Steering Group.&lt;/p&gt;
&lt;h3 id=&quot;contributor-experience-workgroup&quot;&gt;Contributor Experience Workgroup&lt;/h3&gt;
&lt;p&gt;Finally, a new &lt;strong&gt;Contributor Experience Workgroup&lt;/strong&gt; will create new pathways into the open source Swift community, including the Swift Mentorship Program and Community Groups.&lt;/p&gt;
&lt;p&gt;This shift in stewardship will enable the Diversity in Swift champions to focus on diversity being both at the core and pervasive throughout the project and Swift community, while the Contributor Experience group will support all forms of contributing to the Swift project.&lt;/p&gt;
&lt;p&gt;The new Contributor Experience workgroup will explore providing community members with the best support system and mechanics. Some example investments from this new workgroup will be improvements to the process and documentation for contributing code, bug reports, discussion on the Swift Forums, and more.&lt;/p&gt;
&lt;p&gt;For more details, please see the &lt;a href=&quot;/contributor-experience-workgroup&quot;&gt;Contributor Experience Workgroup Charter&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;next-steps-and-you&quot;&gt;Next Steps and You&lt;/h2&gt;
&lt;p&gt;If youre interested in getting involved, check out the charters of the above groups, or read about other ways to &lt;a href=&quot;/contributing/&quot;&gt;contribute to the project&lt;/a&gt;. If you have contributed and dont fall neatly into one of the groups above, keep going! All contributions are valuable.&lt;/p&gt;
&lt;p&gt;If you want to keep up with these changes, we invite you to join us for the kick-off of our Contributor Meeting series, occurring quarterly. Keep an eye out for more information on the Swift forums.&lt;/p&gt;
&lt;p&gt;Onward!&lt;/p&gt;
&lt;h3 id=&quot;previous-related-announcements&quot;&gt;Previous Related Announcements&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;/blog/documentation-workgroup/&quot;&gt;Documentation Workgroup announcement&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/blog/language-workgroup/&quot;&gt;Language Workgroup announcement&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/blog/website-open-source/&quot;&gt;Website Workgroup announcement&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/blog/server-api-workgroup/&quot;&gt;Server Workgroup announcement&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
</entry>
<entry>
<title>Foundation Package Preview Now Available</title>
<author>
<name>Swift.org</name>
</author>
<link href="https://swift.org/blog/foundation-preview-now-available/"/>
<updated>2023-04-26T06:30:00-04:00</updated>
<id>https://swift.org/blog/foundation-preview-now-available/</id>
<content type="html">&lt;p&gt;Im pleased to announce that a preview of the &lt;a href=&quot;https://www.swift.org/blog/future-of-foundation/&quot;&gt;future of Foundation&lt;/a&gt; is now available on &lt;a href=&quot;https://github.com/apple/swift-foundation&quot;&gt;GitHub&lt;/a&gt;!&lt;/p&gt;
&lt;p&gt;This preview provides a unified implementation of Foundation, written in Swift, that is faster, safer, and more approachable to new contributors.&lt;/p&gt;
&lt;p&gt;A new Foundation Workgroup will run reviews of proposed Foundation API and coordinate the needs of the Swift community with Apple engineering.&lt;/p&gt;
&lt;p&gt;While the new package is not yet complete, it provides the first building blocks of our unified Swift implementation and I am eager to provide it to the Swift community for early testing and contributions.&lt;/p&gt;
&lt;h2 id=&quot;current-state&quot;&gt;Current State&lt;/h2&gt;
&lt;p&gt;The following types are available in the preview package, with more to come later. Many types, including &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;JSONEncoder&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Calendar&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TimeZone&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Locale&lt;/code&gt; are all-new Swift implementations. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FormatStyle&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ParseStyle&lt;/code&gt; available as open source for the first time.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;FoundationEssentials&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AttributedString&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Data&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Date&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DateInterval&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;JSONEncoder&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;JSONDecoder&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Predicate&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt; extensions&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UUID&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Internationalization&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Calendar&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TimeZone&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Locale&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DateComponents&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FormatStyle&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ParseStrategy&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For internationalization support on non-Darwin platforms, we created a separate package named &lt;em&gt;&lt;a href=&quot;https://github.com/apple/swift-foundation-icu&quot;&gt;FoundationICU&lt;/a&gt;&lt;/em&gt;. This repository contains the necessary ICU implementations and data from the upstream &lt;a href=&quot;https://github.com/apple-oss-distributions/ICU&quot;&gt;Apple OSS Distribution ICU&lt;/a&gt;. Using a common version of ICU will result in more reliable and consistent results when formatting dates, times and numbers.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Note: The Foundation Preview package depends on the under-development &lt;a href=&quot;https://www.swift.org/download&quot;&gt;Swift 5.9 toolchain&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;performance&quot;&gt;Performance&lt;/h2&gt;
&lt;p&gt;Being written in Swift, this new implementation provides some major benefits over the previous C and Objective-C versions.&lt;/p&gt;
&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Locale&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TimeZone&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Calendar&lt;/code&gt; no longer require bridging from Objective-C. Common tasks like getting a fixed &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Locale&lt;/code&gt; are an order of magnitude faster for Swift clients. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Calendar&lt;/code&gt;s ability to calculate important dates can take better advantage of Swifts value semantics to avoid intermediate allocations, resulting in over a 20% improvement in some benchmarks. Date formatting using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FormatStyle&lt;/code&gt; also has some major performance upgrades, showing a massive 150% improvement in a benchmark of formatting with a standard date and time template.&lt;/p&gt;
&lt;p&gt;Even more exciting are the improvements to JSON decoding in the new package. Foundation has a brand-new Swift implementation for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;JSONDecoder&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;JSONEncoder&lt;/code&gt;, eliminating costly roundtrips to and from the Objective-C collection types. The tight integration of parsing JSON in Swift for initializing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Codable&lt;/code&gt; types improves performance, too. In benchmarks parsing &lt;a href=&quot;https://www.boost.org/doc/libs/master/libs/json/doc/html/json/benchmarks.html&quot;&gt;test data&lt;/a&gt;, there are improvements in decode time from 200% to almost 500%.&lt;/p&gt;
&lt;h2 id=&quot;governance&quot;&gt;Governance&lt;/h2&gt;
&lt;p&gt;The success of the Swift language is a great example of what is possible when a community comes together with a shared interest.&lt;/p&gt;
&lt;p&gt;For Foundation, our goal is to create the best fundamental data types and internationalization features, and make them available to Swift developers everywhere. It will take advantage of emerging features in the language as they are added, and enable library and app authors to build higher level API with confidence.&lt;/p&gt;
&lt;p&gt;Moving Foundation into this future requires not only an improved implementation, but also an improved process for using it outside of Apples platforms. Therefore, Foundation now has a path for the community to add new API for the benefit of Swift developers on every platform.&lt;/p&gt;
&lt;p&gt;The Foundation package is an independent project in its early incubation stages. Inspired by the workgroups in the Swift project, it will have a workgroup to (a) oversee &lt;a href=&quot;https://github.com/apple/swift-foundation/blob/main/Evolution.md&quot;&gt;community API proposals&lt;/a&gt; and (b) to closely coordinate with developments in the Swift project and those on Apples platforms. In the future, we will explore how to sunset the existing &lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation&quot;&gt;swift-corelibs-foundation&lt;/a&gt; and migrate to using the new version of Foundation created by this project.&lt;/p&gt;
&lt;p&gt;The workgroup will meet regularly to review proposals, look at emerging trends in the Swift ecosystem, and discuss how the library can evolve to best meet our common goals. The initial members of the workgroup will be announced in the coming weeks.&lt;/p&gt;
&lt;h2 id=&quot;next-steps&quot;&gt;Next Steps&lt;/h2&gt;
&lt;p&gt;Quality and performance are our two most important goals for the project. Therefore, the plans for the first half of 2023 are continuing refinement of the core API, adding to our suites of unit and performance tests, and expanding to other platforms where possible, using the most relevant code from &lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation&quot;&gt;swift-corelibs-foundation&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;As a secondary goal, the project requests community proposals to add new APIs with focused scope to round out existing API functionality in Foundation. This will pave the way to explore how to add significant new APIs as the project progresses. In 2023, we aim to accept a small number of proposals with corresponding Swift implementations. The experience from reviewing and accepting those new APIs will help to refine the API proposal process and facilitate scaling up to more API contributions in the future.&lt;/p&gt;
&lt;p&gt;Later this year, the porting will continue with high-quality Swift implementations of additional Foundation API such as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;URL&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Bundle&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FileManager&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FileHandle&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Process&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SortDescriptor&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SortComparator&lt;/code&gt; and more.&lt;/p&gt;
&lt;h2 id=&quot;contributions&quot;&gt;Contributions&lt;/h2&gt;
&lt;p&gt;Foundation welcomes contributions from the community. The project uses the &lt;a href=&quot;https://forums.swift.org/c/related-projects/foundation/99&quot;&gt;Swift forums for discussion&lt;/a&gt; and &lt;a href=&quot;https://github.com/apple/swift-foundation/issues&quot;&gt;GitHub Issues&lt;/a&gt; for tracking bugs, feature requests, and other work. Please see the &lt;a href=&quot;https://github.com/apple/swift-foundation/blob/main/CONTRIBUTING.md&quot;&gt;CONTRIBUTING&lt;/a&gt; document for more information, including the process for accepting community contributions for new API in Foundation.&lt;/p&gt;
&lt;p&gt;Im excited to start this new chapter in the development of Foundation.&lt;/p&gt;
</content>
</entry>
<entry>
<title>Swift 5.8 Released!</title>
<author>
<name>Swift.org</name>
</author>
<link href="https://swift.org/blog/swift-5.8-released/"/>
<updated>2023-03-30T11:00:00-04:00</updated>
<id>https://swift.org/blog/swift-5.8-released/</id>
<content type="html">&lt;p&gt;Swift 5.8 is now officially released! 🎉 This release includes major additions to the &lt;a href=&quot;#language-and-standard-library&quot;&gt;language and standard library&lt;/a&gt;, including &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hasFeature&lt;/code&gt; to support piecemeal adoption of upcoming features, an improved &lt;a href=&quot;#developer-experience&quot;&gt;developer experience&lt;/a&gt;, improvements to tools in the Swift ecosystem including &lt;a href=&quot;#swift-docc&quot;&gt;Swift-DocC&lt;/a&gt;, &lt;a href=&quot;#swift-package-manager&quot;&gt;Swift Package Manager&lt;/a&gt;, and &lt;a href=&quot;#swiftsyntax&quot;&gt;SwiftSyntax&lt;/a&gt;, refined &lt;a href=&quot;#windows-platform&quot;&gt;Windows support&lt;/a&gt;, and more.&lt;/p&gt;
&lt;p&gt;Thank you to everyone in the Swift community who made this release possible. Your Swift Forums discussions, bug reports, pull requests, educational content, and other contributions are always appreciated!&lt;/p&gt;
&lt;p&gt;For a quick dive into some of whats new in Swift 5.8, check out this &lt;a href=&quot;https://github.com/twostraws/whats-new-in-swift-5-8&quot;&gt;playground&lt;/a&gt; put together by Paul Hudson.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://docs.swift.org/swift-book/documentation/the-swift-programming-language/&quot;&gt;The Swift Programming Language&lt;/a&gt; book has been updated for Swift 5.8 and is now published with DocC. This is the official Swift guide and a great entry point for those new to Swift. The Swift community also maintains a number of &lt;a href=&quot;/documentation/tspl/#translations&quot;&gt;translations&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;language-and-standard-library&quot;&gt;Language and Standard Library&lt;/h2&gt;
&lt;p&gt;Swift 5.8 enables you to start incrementally preparing your projects for Swift 6 by &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0362-piecemeal-future-features.md&quot;&gt;using &lt;em&gt;upcoming features&lt;/em&gt;&lt;/a&gt;. By default, upcoming features are disabled. To enable a feature, pass the compiler flag &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-enable-upcoming-feature&lt;/code&gt; followed by the features identifier.&lt;/p&gt;
&lt;p&gt;Feature identifiers can also be &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0362-piecemeal-future-features.md#feature-detection-in-source-code&quot;&gt;used in source code&lt;/a&gt; using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#if hasFeature(FeatureIdentifier)&lt;/code&gt; so that code can still compile with older tools where the upcoming feature is not available.&lt;/p&gt;
&lt;p&gt;Swift 5.8 includes upcoming features for the following Swift evolution proposals:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;SE-0274: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0274-magic-file.md&quot;&gt;Concise magic file names&lt;/a&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ConciseMagicFile&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;SE-0286: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0286-forward-scan-trailing-closures.md&quot;&gt;Forward-scan matching for trailing closures&lt;/a&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ForwardTrailingClosures&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;SE-0335: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md&quot;&gt;Introduce existential any&lt;/a&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ExistentialAny&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;SE-0354: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0354-regex-literals.md&quot;&gt;Regex literals&lt;/a&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;BareSlashRegexLiterals&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For example, building the following file at &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/Users/example/Desktop/0274-magic-file.swift&lt;/code&gt; in a module called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MagicFile&lt;/code&gt; with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-enable-experimental-feature ConciseMagicFile&lt;/code&gt; will opt into the concise format for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#file&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#filePath&lt;/code&gt; described in SE-0274:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;#file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;#filePath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;fatalError&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Something bad happened!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;The above code will produce the following output:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;MagicFile/0274-magic-file.swift
/Users/example/Desktop/0274-magic-file.swift
Fatal error: Something bad happened!: file MagicFile/0274-magic-file.swift, line 3
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Swift 5.8 also includes &lt;em&gt;conditional attributes&lt;/em&gt; to reduce the maintenance cost of libraries that support multiple Swift tools versions. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#if&lt;/code&gt; checks can now surround attributes on a declaration, and a new &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hasAttribute(AttributeName)&lt;/code&gt; conditional directive can be used to check whether the compiler version has support for the attribute with the name &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AttributeName&lt;/code&gt; in the current language mode:&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;#if hasAttribute(preconcurrency)&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;@preconcurrency&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#endif&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;protocol&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;P&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Sendable&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Swift 5.8 brings other language and standard library enhancements, including &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0375-opening-existential-optional.md&quot;&gt;unboxing for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;any&lt;/code&gt; arguments to optional parameters&lt;/a&gt;, &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0373-vars-without-limits-in-result-builders.md&quot;&gt;local wrapped properties in result builders&lt;/a&gt;, &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0369-add-customdebugdescription-conformance-to-anykeypath.md&quot;&gt;improved debug printing for key paths&lt;/a&gt;, and more.&lt;/p&gt;
&lt;p&gt;You can find the complete list of Swift Evolution proposals that were implemented in Swift 5.8 in the &lt;a href=&quot;#swift-evolution-appendix&quot;&gt;Swift Evolution Appendix&lt;/a&gt; below.&lt;/p&gt;
&lt;h2 id=&quot;developer-experience&quot;&gt;Developer Experience&lt;/h2&gt;
&lt;h3 id=&quot;improved-result-builder-implementation&quot;&gt;Improved Result Builder Implementation&lt;/h3&gt;
&lt;p&gt;The result builder implementation has been reworked in Swift 5.8 to greatly improve compile-time performance, code completion results, and diagnostics. The Swift 5.8 result builder implementation enforces stricter type inference that matches the semantics in &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0289-result-builders.md&quot;&gt;SE-0289: Result Builders&lt;/a&gt;, which has an impact on some existing code that relied on invalid type inference.&lt;/p&gt;
&lt;p&gt;The new implementation takes advantage of the &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0326-extending-multi-statement-closure-inference.md&quot;&gt;extended multi-statement closure inference&lt;/a&gt; introduced in Swift 5.7 and applies the result builder transformation exactly as specified by the result builder proposal - a source-level transformation which is type-checked like a multi-statement closure. Doing so enables the compiler to take advantage of all the benefits of the improved closure inference for result builder-transformed code, including optimized type-checking performance (especially in invalid code) and improved error messages.&lt;/p&gt;
&lt;p&gt;For more details, please refer to the &lt;a href=&quot;https://forums.swift.org/t/improved-result-builder-implementation-in-swift-5-8/63192&quot;&gt;Swift Forums post&lt;/a&gt; that outlines the improvements and provides more information about invalid inference scenarios.&lt;/p&gt;
&lt;h2 id=&quot;ecosystem&quot;&gt;Ecosystem&lt;/h2&gt;
&lt;h3 id=&quot;swift-docc&quot;&gt;Swift-DocC&lt;/h3&gt;
&lt;p&gt;As &lt;a href=&quot;https://www.swift.org/blog/tspl-on-docc/&quot;&gt;announced in February&lt;/a&gt;, The Swift Programming Language book has been converted to Swift-DocC and made &lt;a href=&quot;https://github.com/apple/swift-book&quot;&gt;open source&lt;/a&gt;, and with it came some enhancements to Swift-DocC itself in the form of &lt;a href=&quot;https://www.swift.org/documentation/docc/options&quot;&gt;option directives&lt;/a&gt; you can use to change the behavior of your generated documentation. Swift-DocC has also added some new directives to create more &lt;a href=&quot;https://www.swift.org/documentation/docc/api-reference-syntax#creating-custom-page-layouts&quot;&gt;dynamic documentation pages&lt;/a&gt;, including &lt;a href=&quot;https://www.swift.org/documentation/docc/row&quot;&gt;Grid-based layouts&lt;/a&gt; and &lt;a href=&quot;https://www.swift.org/documentation/docc/tab&quot;&gt;tab navigators&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;To take things even further, you can now &lt;a href=&quot;https://www.swift.org/documentation/docc/customizing-the-appearance-of-your-documentation-pages&quot;&gt;customize the appearance of your documentation pages&lt;/a&gt; with color, font, and icon customizations. Navigation also took a step forward with quick navigation, allowing fuzzy in-project search:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/5.8-blog/docc-fuzzy-search.png&quot; alt=&quot;A DocC documentation page showing a quick navigation overlay showing fuzzy documentation search&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Swift-DocC also now supports documenting extensions to types from other modules. This is an opt-in feature and can be &lt;a href=&quot;https://apple.github.io/swift-docc-plugin/documentation/swiftdoccplugin/generating-documentation-for-extended-types&quot;&gt;enabled by adding the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--include-extended-types&lt;/code&gt; flag when using the Swift-DocC plugin&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/5.8-blog/docc-extended-type.png&quot; alt=&quot;A documentation page featuring an extension to the standard library&apos;s Collection type.&quot; /&gt;&lt;/p&gt;
&lt;h3 id=&quot;swift-package-manager&quot;&gt;Swift Package Manager&lt;/h3&gt;
&lt;p&gt;Following are some highlights from the changes introduced to the &lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;Swift Package Manager&lt;/a&gt; in Swift 5.8:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0362-piecemeal-future-features.md&quot;&gt;SE-0362&lt;/a&gt;: Targets can now specify the upcoming language features they require. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Package.swift&lt;/code&gt; manifest syntax has been expanded with an API to include setting &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;enableUpcomingFeature&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;enableExperimentalFeature&lt;/code&gt; flags at the target level.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0378-package-registry-auth.md&quot;&gt;SE-0378&lt;/a&gt;: Token authentication when interacting with a package registry is now supported. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift package-registry&lt;/code&gt; command has two new subcommands &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;login&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;logout&lt;/code&gt; for adding/removing registry credentials.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Exposing an executable product that consists solely of a binary target that is backed by an artifact bundle is now allowed. This allows vending binary executables as their own separate package, independently of the plugins that are using them.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In packages using tools version 5.8 or later, Foundation is no longer implicitly imported into package manifests. If Foundation APIs are used, the module needs to be imported explicitly.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;See the &lt;a href=&quot;https://github.com/apple/swift-package-manager/blob/main/CHANGELOG.md#swift-58&quot;&gt;Swift Package Manager changelog&lt;/a&gt; for the complete list of changes.&lt;/p&gt;
&lt;h3 id=&quot;swiftsyntax&quot;&gt;SwiftSyntax&lt;/h3&gt;
&lt;p&gt;With the Swift 5.8-aligned release of &lt;a href=&quot;https://github.com/apple/swift-syntax&quot;&gt;SwiftSyntax&lt;/a&gt;, SwiftSyntax contains a completely re-written parser that is implemented entirely in Swift instead of relying on the C++ parser to produce a SwiftSyntax tree. While the Swift compiler still uses the old parser implemented in C++, the eventual goal is to replace the old parser entirely. The new parser has a number of advantages:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Contributing to or depending on SwiftSyntax is now as easy as any other Swift package. This greatly lowers the barrier of entry for new contributors and adopters.&lt;/li&gt;
&lt;li&gt;The new parser has been designed with error recovery as a primary goal. It is more tolerant of parsing errors and produces better error messages.&lt;/li&gt;
&lt;li&gt;SwiftSyntaxBuilder allows generating source code in a declarative way using a mixture of result builders and string interpolation. An example can be found &lt;a href=&quot;https://github.com/apple/swift-syntax/blob/release/5.8/Examples/CodeGenerationUsingSwiftSyntaxBuilder.swift&quot;&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;windows-platform&quot;&gt;Windows Platform&lt;/h3&gt;
&lt;p&gt;Swift 5.8 continues the incremental improvements to the Windows toolchain. Some of the important work that has gone into this release cycle includes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The Windows toolchain has reduced some of its dependency on environment variables. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DEVELOPER_DIR&lt;/code&gt; was previously needed to locate components and this is no longer required. This cleans up the installation and enables us to get closer to per-user installation.&lt;/li&gt;
&lt;li&gt;ICU has been changed to static linking. This reduces the number of files that need to be distributed and reduces the number of dependencies that a shipping product requires. This was made possible by the removal of the ICU dependency in the Swift standard library.&lt;/li&gt;
&lt;li&gt;Some of the initial work to support C++ interop on Windows has been merged and is available in the toolchain. This includes the work towards modularising the Microsoft C++ Runtime (msvcprt).&lt;/li&gt;
&lt;li&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;vcruntime&lt;/code&gt; module has been renamed to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;visualc&lt;/code&gt;. This better reflects the module and paves the road for future enhancements for bridging the Windows platform libraries.&lt;/li&gt;
&lt;li&gt;A significant amount of work for improving path handling in the Swift Package Manager has been merged. This should help make Swift Package Manager more robust on Windows and improve interactions with SourceKit-LSP.&lt;/li&gt;
&lt;li&gt;SourceKit-LSP has benefited from several robustness improvements. Cross-module references are now more reliable and C/C++ references have been improved thanks to the enhanced path handling in SwiftPM which ensures that files are correctly identified.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;downloads&quot;&gt;Downloads&lt;/h2&gt;
&lt;p&gt;Official binaries are &lt;a href=&quot;https://swift.org/download/&quot;&gt;available for download&lt;/a&gt; from &lt;a href=&quot;http://swift.org/&quot;&gt;Swift.org&lt;/a&gt; for Xcode, Windows, and Linux. The Swift 5.8 compiler is also included in &lt;a href=&quot;https://apps.apple.com/app/xcode/id497799835&quot;&gt;Xcode 14.3&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;swift-evolution-appendix&quot;&gt;Swift Evolution Appendix&lt;/h2&gt;
&lt;p&gt;The following language, standard library, and Swift Package Manager proposals were accepted through the &lt;a href=&quot;https://github.com/apple/swift-evolution&quot;&gt;Swift Evolution&lt;/a&gt; process and &lt;a href=&quot;https://apple.github.io/swift-evolution/#?version=5.8&quot;&gt;implemented in Swift 5.8&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Language and Standard Library&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;SE-0274: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0274-magic-file.md&quot;&gt;Concise magic file names&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SE-0362: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0362-piecemeal-future-features.md&quot;&gt;Piecemeal adoption of upcoming language improvements&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SE-0365: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0365-implicit-self-weak-capture.md&quot;&gt;Allow implicit self for weak self captures, after self is unwrapped&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SE-0367: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0367-conditional-attributes.md&quot;&gt;Conditional compilation for attributes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SE-0368: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0368-staticbigint.md&quot;&gt;StaticBigInt&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SE-0369: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0369-add-customdebugdescription-conformance-to-anykeypath.md&quot;&gt;Add CustomDebugStringConvertible conformance to AnyKeyPath&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SE-0370: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0370-pointer-family-initialization-improvements.md&quot;&gt;Pointer Family Initialization Improvements and Better Buffer Slices&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SE-0372: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0372-document-sorting-as-stable.md&quot;&gt;Document Sorting as Stable&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SE-0373: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0373-vars-without-limits-in-result-builders.md&quot;&gt;Lift all limitations on variables in result builders&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SE-0375: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0375-opening-existential-optional.md&quot;&gt;Opening existential arguments to optional parameters&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SE-0376: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0376-function-back-deployment.md&quot;&gt;Function Back Deployment&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Swift Package Manager&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;SE-0362: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0362-piecemeal-future-features.md&quot;&gt;Piecemeal adoption of upcoming language improvements&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SE-0378: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0378-package-registry-auth.md&quot;&gt;Package Registry Authentication&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
</entry>
<entry>
<title>Swift Package Index gains Apple sponsorship</title>
<author>
<name>Swift.org</name>
</author>
<link href="https://swift.org/blog/swift-package-index-developer-spotlight/"/>
<updated>2023-03-24T04:00:00-04:00</updated>
<id>https://swift.org/blog/swift-package-index-developer-spotlight/</id>
<content type="html">&lt;p&gt;Building a thriving open source ecosystem is important to Swifts success, and open source packages are the building blocks that help power countless Swift projects. As the number of packages increases, discovery becomes critical for developers needing to find the tools and libraries that help them build their apps and services.&lt;/p&gt;
&lt;p&gt;Over the last three years, the &lt;a href=&quot;https://swiftpackageindex.com&quot;&gt;Swift Package Index&lt;/a&gt; has become a popular destination for searching and discovering packages to help developers with their work.&lt;/p&gt;
&lt;p&gt;Recognizing the valuable resource the Swift Package Index provides to the community, the service is now sponsored by Apple.&lt;/p&gt;
&lt;p&gt;The post below is a Developer Spotlight from Swift Package Index creators &lt;a href=&quot;https://daveverwer.com&quot;&gt;Dave Verwer&lt;/a&gt; and &lt;a href=&quot;https://mastodon.social/@finestructure&quot;&gt;Sven A. Schmidt&lt;/a&gt; about their journey building the index into what it is today.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Our goal for the Swift Package Index has always been to help people make better decisions about the package dependencies they include in their projects.&lt;/p&gt;
&lt;p&gt;When we first launched the website in 2020, we initially tackled package metadata and search. The site polls a &lt;a href=&quot;https://github.com/SwiftPackageIndex/PackageList/blob/main/packages.json&quot;&gt;list of known packages&lt;/a&gt;, clones every repository, analyses the package manifest and git history, and makes that metadata searchable. Its more than a simple metadata search, though, and we designed the package page to expose essential information that enables developers to make informed decisions about their dependencies. It answers questions like how long a package has been in development, how the author has licensed the code, whether pull requests and issues are being monitored and responded to, and more. At first glance, a package page on the index can look similar to its GitHub repository page, but we focus the metadata to be relevant to potential user of the package.&lt;/p&gt;
&lt;p&gt;As the site grew, we decided to add package compatibility testing. Swift packages can be used in apps across various platforms but theres no easy way to determine compatibility for each platform. How did we tackle it? If youre imagining that we attempt to build each package in the index for every permutation of four Swift versions and five platforms every time the default branch moves forward or the author tags a release, youd be correct! The “build system”, as we now call it, processes an average of 5,000 builds per day and has completed more than five million builds in total. Its such a large operation that it needs its own custom monitoring app:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/swift-package-index-developer-spotlight-blog/pipelines-app.png&quot; alt=&quot;A screenshot of the internal Swift Package Index app, Pipelines. It shows the status of several pending, running, passed, and failed package builds.&quot; /&gt;&lt;/p&gt;
&lt;p&gt;All those build results go to build the concise compatibility matrix that shows the platform and Swift version requirements you see on &lt;a href=&quot;https://swiftpackageindex.com/apple/swift-markdown&quot;&gt;every package page&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Last year we turned to documentation. Highlighting packages that have documentation aligns with the sites goal of making better decisions about dependencies, but we decided that detecting and highlighting wasnt enough. Instead, we decided to offer the community a platform to build and host versioned documentation for free. Any package author can now opt-in to documentation generation, and once the build system has completed a successful build, well host versioned DocC documentation. You can see an example of this with the &lt;a href=&quot;https://swiftpackageindex.com/apple/swift-markdown/documentation&quot;&gt;documentation for swift-markdown&lt;/a&gt;. The community adopted this feature quickly, and we now have 300+ packages opted in, and our storage requirements are climbing quickly:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/swift-package-index-developer-spotlight-blog/docc-storage-growth.png&quot; alt=&quot;A chart showing documentation storage rising over time from zero in May 2022 to 35Gb in February 2023 with a sharp increase at the end of December 2022&quot; /&gt;&lt;/p&gt;
&lt;p&gt;The Swift Package Index doesnt &lt;em&gt;merely&lt;/em&gt; index Swift packages, it &lt;em&gt;is an&lt;/em&gt; open-source Swift package! It runs as a &lt;a href=&quot;https://swiftpackageindex.com/vapor/vapor&quot;&gt;vapor&lt;/a&gt; app and depends on many other packages, such as &lt;a href=&quot;https://swiftpackageindex.com/vapor/fluent&quot;&gt;fluent&lt;/a&gt; and the &lt;a href=&quot;https://swiftpackageindex.com/vapor/fluent-postgres-driver&quot;&gt;Postgres driver&lt;/a&gt; for database access, &lt;a href=&quot;https://swiftpackageindex.com/JohnSundell/Plot&quot;&gt;Plot&lt;/a&gt; and &lt;a href=&quot;https://swiftpackageindex.com/JohnSundell/Ink&quot;&gt;Ink&lt;/a&gt; to render HTML, &lt;a href=&quot;https://swiftpackageindex.com/pointfreeco/swift-snapshot-testing&quot;&gt;swift-snapshot-testing&lt;/a&gt; for testing, and more.&lt;/p&gt;
&lt;p&gt;Running a site like this takes constant maintenance, and we have merged more than 1,200 pull requests and deployed over 600 releases (about four per week) since launching three years ago. We also have a growing community of &lt;a href=&quot;https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/graphs/contributors&quot;&gt;external contributors&lt;/a&gt; that help improve the site every day.&lt;/p&gt;
&lt;p&gt;Finally, with the community in mind, we also started a podcast called &lt;a href=&quot;https://swiftpackageindexing.transistor.fm&quot;&gt;Swift Package Indexing&lt;/a&gt;, where we discuss progress with feature development and pick a selection of packages from around the community for each episode.&lt;/p&gt;
&lt;p&gt;We couldnt be more proud to see Apple support our project and join our &lt;a href=&quot;https://swiftpackageindex.com/supporters&quot;&gt;other community and corporate sponsors&lt;/a&gt; to ensure we can continue providing this service for many more years to come. Thank you to Apple and everyone who makes it possible to run this site.&lt;/p&gt;
</content>
</entry>
<entry>
<title>Introducing Swift Certificates and Swift ASN.1</title>
<author>
<name>Swift.org</name>
</author>
<link href="https://swift.org/blog/swift-certificates-and-asn1/"/>
<updated>2023-03-07T05:00:00-04:00</updated>
<id>https://swift.org/blog/swift-certificates-and-asn1/</id>
<content type="html">&lt;p&gt;Im excited to announce two new open source Swift packages: &lt;a href=&quot;https://github.com/apple/swift-certificates&quot;&gt;swift-certificates&lt;/a&gt; and &lt;a href=&quot;https://github.com/apple/swift-asn1&quot;&gt;swift-asn1&lt;/a&gt;. Together, these libraries provide developers a faster and safer implementation of X.509 certificates, a critical technology that powers the security of TLS.&lt;/p&gt;
&lt;h2 id=&quot;x509-and-asn1&quot;&gt;X.509 and ASN.1&lt;/h2&gt;
&lt;h3 id=&quot;what-are-x509-certificates&quot;&gt;What are X.509 certificates?&lt;/h3&gt;
&lt;p&gt;X.509 certificates are a commonly-used identity format to cryptographically attest to the identity of an actor in a system. They form part of the X.509 standard for defining a public key infrastructure (PKI). X.509-style PKIs are commonly used in cases where it is necessary to delegate the authority to attest to an actors identity to a small number of trusted parties, called Certificate Authorities.&lt;/p&gt;
&lt;p&gt;Most of us experience X.509 in the form of TLS certificates, but they have a wide range of other uses such as code-signing and token exchange.&lt;/p&gt;
&lt;p&gt;Server-side applications make frequent use of X.509 certificates. At a minimum, most web servers will load a TLS certificate to secure their network connections.&lt;/p&gt;
&lt;p&gt;Many more complex use cases exist, from dynamically provisioning TLS certificates using &lt;a href=&quot;https://www.rfc-editor.org/rfc/rfc8555.html&quot;&gt;ACME&lt;/a&gt; to validating identities using x5c. This makes a fully-featured X.509 library a powerful asset for a server-side ecosystem.&lt;/p&gt;
&lt;h3 id=&quot;what-is-asn1&quot;&gt;What is ASN.1?&lt;/h3&gt;
&lt;p&gt;The layout of the X.509 certificate type is defined using a data type definition language called ASN.1 (Abstract Syntax Notation One).&lt;/p&gt;
&lt;p&gt;ASN.1 is extremely flexible and complex. Types can be defined and recursively referenced. Fields can be named and tagged. Fields can be optional or defaulted. Human readable comments can be applied, often applying further constraints on top of what ASN.1 is capable of expressing.&lt;/p&gt;
&lt;p&gt;ASN.1 is the name of the format used to define the types, but there is more than one method of serializing an ASN.1 type. These methods are called “encoding rules” and there are a lot of them. The vast majority of cryptographic use cases for ASN.1 use the Distinguished Encoding Rules (DER) or the Basic Encoding Rules (BER).&lt;/p&gt;
&lt;p&gt;For the certificates use case, the fact that X.509 certificates are defined in ASN.1 and serialized using DER means that in order to provide a powerful, safe, Swift-native X.509 library, we need to build out an ASN.1 library as well.&lt;/p&gt;
&lt;h2 id=&quot;new-packages&quot;&gt;New Packages&lt;/h2&gt;
&lt;h3 id=&quot;swift-asn1&quot;&gt;Swift ASN.1&lt;/h3&gt;
&lt;p&gt;Swift ASN.1 provides two major pieces of functionality: an implementation of the common ASN.1 currency types, and an implementation of DER serialization and deserialization. This is sufficient for implementation of the majority of the cryptographic use cases for DER, including for swift-certificates.&lt;/p&gt;
&lt;p&gt;Swift ASN.1 provides these security-critical parsing and serializing services using entirely memory-safe code with low overhead.&lt;/p&gt;
&lt;p&gt;Making this parser safe is particularly valuable as a major goal of DER parsers is to parse untrusted user input. Memory safety bugs in ASN.1 parsing commonly lead to high severity issues.&lt;/p&gt;
&lt;h3 id=&quot;swift-certificates&quot;&gt;Swift Certificates&lt;/h3&gt;
&lt;p&gt;Swift Certificates has been released at an early stage in order to get community feedback, so its missing some functionality that will be needed for widespread use. Right now it can:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Parse the majority of X.509 certificates that comply with RFC 5280 and are used in the Web PKI.&lt;/li&gt;
&lt;li&gt;Perform X.509 chain building.&lt;/li&gt;
&lt;li&gt;Support pluggable X.509 verification policies.&lt;/li&gt;
&lt;li&gt;Support pluggable OCSP resolution.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Version 1.0 will be ready once the package has a sufficiently robust X.509 verifier that can safely support the WebPKI use case.&lt;/p&gt;
&lt;p&gt;Our medium-term goal is to replace swift-nio-ssls BoringSSL-based X.509 implementation with Swift Certificates. This should provide substantial performance improvements to all applications using TLS and add memory safety to a substantial attack surface. We also intend to add support for Certificate Signing Requests, opening the door for more automated interaction with certificate issuance services.&lt;/p&gt;
&lt;h2 id=&quot;get-involved&quot;&gt;Get involved&lt;/h2&gt;
&lt;p&gt;Please keep an eye on the repositories (&lt;a href=&quot;https://github.com/apple/swift-certificates&quot;&gt;swift-certificates&lt;/a&gt;, &lt;a href=&quot;https://github.com/apple/swift-asn1&quot;&gt;swift-asn1&lt;/a&gt;), open issues and pull requests, and try to use the code and report back.&lt;/p&gt;
&lt;p&gt;Were really excited for what Swift Certificates can do for the Swift community, and we look forward to seeing it unlock a wide range of new use-cases and technologies.&lt;/p&gt;
</content>
</entry>
<entry>
<title>“The Swift Programming Language” book now published with DocC</title>
<author>
<name>Swift.org</name>
</author>
<link href="https://swift.org/blog/tspl-on-docc/"/>
<updated>2023-02-16T10:00:00-04:00</updated>
<id>https://swift.org/blog/tspl-on-docc/</id>
<content type="html">&lt;p&gt;Were happy to announce that &lt;a href=&quot;https://docs.swift.org/swift-book/documentation/the-swift-programming-language/&quot;&gt;The Swift Programming Language&lt;/a&gt; book (TSPL) is now published using &lt;a href=&quot;https://github.com/apple/swift-docc&quot;&gt;Swift-DocC&lt;/a&gt;, starting with Swift 5.8. TSPL is now ready to start accepting content contributions, under the direction of the Swift Documentation Workgroup.&lt;/p&gt;
&lt;p&gt;This is a major step for the book. It was first release as open source in August 2022 and since then, weve merged over 50 pull requests as we converted to DocC. We also made enhancements to DocC based on what we learned working on the book, like adding control over automatic see-also sections and new on-page navigation. Other DocC content that guides developers through a linear narrative, like the documentation for large or complex packages, can also take advantage of these enhancements.&lt;/p&gt;
&lt;h2 id=&quot;get-involved&quot;&gt;Get involved&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Contribute content to TSPL.&lt;/strong&gt;
For some ideas of what you can write about, see the projects &lt;a href=&quot;https://github.com/apple/swift-book/milestone/2&quot;&gt;GitHub issues page&lt;/a&gt; and the recently accepted &lt;a href=&quot;https://www.swift.org/swift-evolution/&quot;&gt;Swift Evolution proposals&lt;/a&gt;. For details about making contributions, see the &lt;a href=&quot;https://github.com/apple/swift-book/blob/main/CONTRIBUTING.md&quot;&gt;CONTRIBUTING.md&lt;/a&gt; file in the Git repository, including when to pitch large changes in the &lt;a href=&quot;https://forums.swift.org/c/92&quot;&gt;Swift Documentation forum category&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Contribute to a translation project.&lt;/strong&gt;
&lt;a href=&quot;https://www.swift.org/documentation/tspl/#translations&quot;&gt;Translations&lt;/a&gt; of TSPL can now use the same publication pipeline as the English version of TSPL. Contributors to translations can follow changes in the English version by watching pitch threads on the Swift forum and pull requests in GitHub.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Improve DocC support for long-form content.&lt;/strong&gt;
There are more opportunities to contribute to an improved documentation experience, like adding support for interactive and offline content, and support for tested code listings. For more ideas, see the GitHub issues pages for &lt;a href=&quot;https://github.com/apple/swift-book/milestone/2&quot;&gt;TSPL&lt;/a&gt; and &lt;a href=&quot;https://github.com/apple/swift-docc/issues&quot;&gt;DocC&lt;/a&gt;.&lt;/p&gt;
</content>
</entry>
<entry>
<title>The Future of Foundation</title>
<author>
<name>Swift.org</name>
</author>
<link href="https://swift.org/blog/future-of-foundation/"/>
<updated>2022-12-09T04:00:00-04:00</updated>
<id>https://swift.org/blog/future-of-foundation/</id>
<content type="html">&lt;p&gt;The Foundation framework is used in nearly all Swift projects. It provides both a base layer of functionality for fundamentals like strings, collections, and dates, as well as setting conventions for writing great Swift code.&lt;/p&gt;
&lt;p&gt;Today, we have some exciting announcements for the future of Foundation.&lt;/p&gt;
&lt;h2 id=&quot;going-open&quot;&gt;Going Open&lt;/h2&gt;
&lt;p&gt;When Swift &lt;a href=&quot;/blog/welcome/&quot;&gt;began life as an open source project&lt;/a&gt;, we wanted to open not just the language itself, but the ecosystem around it. Foundation has been instrumental in the success of decades of software and has been an integral part of the Swift developer experience from the beginning, and we knew it had to be included in the open source offering.&lt;/p&gt;
&lt;p&gt;The &lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation&quot;&gt;swift-corelibs-foundation&lt;/a&gt; project helped launch the open source Swift version of Foundation in 2016, wrapping a Swift layer around the preexisting, open source C implementation of Foundation.&lt;/p&gt;
&lt;p&gt;In the intervening years, Swift has grown both technologically (e.g. ABI stability), as well as socially, attracting a diverse community of participants bound together by their interest in Swift.&lt;/p&gt;
&lt;p&gt;With that growth, the time has come to reevaluate the strategy of an open source Foundation.&lt;/p&gt;
&lt;h2 id=&quot;going-further&quot;&gt;Going Further&lt;/h2&gt;
&lt;p&gt;Today, we are announcing a new open source Foundation project, written in Swift, for Swift.&lt;/p&gt;
&lt;p&gt;This achieves a number of technical goals:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;No more wrapped C code.&lt;/strong&gt; With a native Swift implementation of Foundation, the framework no longer pays conversion costs between C and Swift, resulting in faster performance. A Swift implementation, developed as a package, also makes it easier for Swift developers to inspect, understand, and contribute code.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Provide the option of smaller, more granular packages.&lt;/strong&gt; Rewriting Foundation provides an opportunity to match its architecture to evolving use cases. Developers want to keep their binary sizes small, and a new &lt;em&gt;FoundationEssentials&lt;/em&gt; package will provide the most important types in Foundation with no system dependencies to help accomplish this. A separate &lt;em&gt;FoundationInternationalization&lt;/em&gt; package will be available when you need to work with localized content such as formatted dates and time. Other packages will continue to provide XML support and networking. A new &lt;em&gt;FoundationObjCCompatibility&lt;/em&gt; package will contain legacy APIs which are useful for certain applications.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Unify Foundation implementations.&lt;/strong&gt; Multiple implementations of any API risks divergent behavior and ultimately bugs when moving code across platforms. This new Foundation package will serve as the core of a single, canonical implementation of Foundation, regardless of platform.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;And this also achieves an important community goal:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Open contribution process.&lt;/strong&gt; Open source projects are at their best when the community of users can participate and become a community of developers. A new, open contribution process will be available to enable all developers to contribute new API to Foundation.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;going-together&quot;&gt;Going Together&lt;/h2&gt;
&lt;p&gt;Were excited to start discussing these plans with everyone &lt;a href=&quot;https://forums.swift.org/t/what-s-next-for-foundation/61939&quot;&gt;on the Swift forums&lt;/a&gt;. The project itself will launch on GitHub in 2023.&lt;/p&gt;
</content>
</entry>
</feed>