<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:media="http://search.yahoo.com/mrss/">
<channel>
<title>Issues — EvolutionKit</title>
<description>Your guide to Swift Evolution — tracking proposals, changes, and what&apos;s coming next in the Swift language.</description>
<link>https://evolutionkit.dev/blog/</link>
<language>en</language>
<atom:link href="https://evolutionkit.dev/blog/feed.xml" rel="self" type="application/rss+xml"/>
<item>
<title>Swift Evolution Monthly: May-November 2024</title>
<link>https://evolutionkit.dev/blog/swift-evolution-monthly-may-november-2024/</link>
<guid isPermaLink="true">https://evolutionkit.dev/blog/swift-evolution-monthly-may-november-2024/</guid>
<pubDate>Thu, 21 Nov 2024 00:00:00 +0000</pubDate>
<description><![CDATA[Discover the latest Swift updates, from Objective-C compatibility improvements to metatype keypaths, trailing commas, and new compiler controls—plus a must-have app for tracking proposals!]]></description>
<content:encoded><![CDATA[<p><img src="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-may-november-2024/hero.webp" alt="Swift Evolution Monthly: May-November 2024" /></p><p>Swift’s GitHub repositories have officially moved from the Apple organization to the new <a href="https://www.swift.org/blog/swiftlang-github/"><code>swiftlang</code> organization</a> during the summer, signaling a significant step in Swift’s evolution as a community-driven language. Meanwhile, Swift 6 brought major advances in concurrency and data-race safety. But since those changes are already well-documented in other places, I will skip the concurrency topic and focus on other improvements to Swift that are around the corner.</p><p>Looking ahead, Swift’s evolution isn’t just about concurrency. Ongoing efforts, such as the proposed Vision document for <a href="https://forums.swift.org/t/prospective-vision-optional-strict-memory-safety-for-swift/75090">Strictly-Safe Swift</a>, are expanding the language’s capabilities beyond app development, particularly in embedded systems or system-level programming. That said, this newsletter remains grounded in what matters most to app developers. So let’s dive in!</p><h2 id="accepted-proposal-summaries">Accepted Proposal Summaries</h2><h3 id="se-0436-objective-c-implementations-in-swift">SE-0436: Objective-C implementations in Swift</h3><p><em><strong>Links</strong></em>: 📝 <a href="https://github.com/swiftlang/swift-evolution/blob/main/proposals/0436-objc-implementation.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0436-objective-c-implementations-in-swift/71712">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0436-objective-c-implementations-in-swift/72053">Acceptance</a></p><p>A new syntax allows implementing Objective-C headers in Swift while maintaining full backward compatibility. This is particularly valuable when modernizing existing iOS apps with Swift while keeping Objective-C compatibility:</p><pre><code class="language-objc">// MyView.h
@interface MyView : UIView
@property (nonatomic) CGFloat cornerRadius;
- (void)animate;
@end</code></pre><pre><code class="language-swift">// MyView.swift
@objc @implementation extension MyView {
    var cornerRadius: CGFloat = 0 {
        didSet { layer.cornerRadius = cornerRadius }
    }

    func animate() {
        // Swift implementation that's fully compatible with Objective-C
    }
}</code></pre><p>This bridges the gap between modern Swift development and legacy Objective-C code, making gradual migration easier. While most relevant for teams maintaining Objective-C codebases, it’s useful for any iOS developer working with mixed codebases or third-party Objective-C frameworks. And certainly Apple system engineers modernizing old system frameworks using Swift.</p><h3 id="se-0438-metatype-keypaths">SE-0438: Metatype Keypaths</h3><p><em><strong>Links</strong></em>: 📝 <a href="https://github.com/swiftlang/swift-evolution/blob/main/proposals/0438-metatype-keypath.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0438-metatype-keypaths/72172">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0438-metatype-keypaths/72878">Acceptance</a></p><p>This proposal allows keypath expressions to access static properties in Swift, introducing metatype keypaths using the <code>.Type</code> syntax.</p><p>Here’s a practical example of how it simplifies code, especially when working with databases or property wrappers:</p><pre><code class="language-swift">struct User {
    static let tableName = &quot;users&quot;
    static let primaryKey = &quot;id&quot;
}

// Before: Required workarounds or verbose syntax
let table = database.table(named: User.tableName)

// After: Can use keypaths directly
let tableKeyPath = \User.Type.tableName
let table = database[keyPath: tableKeyPath]</code></pre><p>This is a moderate improvement that will be particularly valuable for developers working with frameworks that use keypaths extensively (like SwiftData or other database layers) and those building property wrapper-based systems. While not revolutionary, it removes an annoying limitation that required developers to create workarounds for accessing static properties through keypaths.</p><p>Now, we’re just missing <a href="https://forums.swift.org/t/enum-case-keypaths/60899">Enum Case Keypaths</a> – I hope we get them soon!</p><h3 id="se-0439-allow-trailing-comma-in-comma-separated-lists">SE-0439: Allow trailing comma in comma-separated lists</h3><p><em><strong>Links</strong></em>: 📝 <a href="https://github.com/swiftlang/swift-evolution/blob/main/proposals/0439-trailing-comma-lists.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0439-allow-trailing-comma-in-comma-separated-lists/72876">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-with-modifications-se-0439-allow-trailing-comma-in-comma-separated-lists/73216">Acceptance</a></p><p>This proposal extends Swift’s existing trailing comma support (currently limited to arrays and dictionaries) to all comma-separated lists that have clear terminators, like function parameters and tuples.</p><p>Here’s a practical example showing how it improves code maintenance, especially with version control:</p><pre><code class="language-swift">func fetchUser(
    id: String,
    includeDetails: Bool = true,
    cachePolicy: CachePolicy = .default, // Adding/removing params now cleaner
) {
    // ...
}

let coordinates = (
    latitude: 37.7749,
    longitude: -122.4194,
) // Better diffs when modifying values</code></pre><p>This is a small but meaningful quality-of-life improvement that will be particularly appreciated by developers working on large codebases where code formatting and version control cleanliness are important. It reduces noise in git diffs and makes code reorganization smoother. Nice to see these kinds of improvements!</p><h3 id="se-0443-precise-control-flags-over-compiler-warnings">SE-0443: Precise Control Flags over Compiler Warnings</h3><p><em><strong>Links</strong></em>: 📝 <a href="https://github.com/swiftlang/swift-evolution/blob/main/proposals/0443-warning-control-flags.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0443-precise-control-flags-over-compiler-warnings/74116">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0443-precise-control-flags-over-compiler-warnings/74377">Acceptance</a></p><p>Swift adds granular control over compiler warnings, allowing developers to selectively upgrade warnings to errors or keep certain warnings as warnings. This is particularly valuable when maintaining large codebases:</p><pre><code class="language-swift">// See which group a warning belongs to
swiftc -print-diagnostic-groups MyApp.swift

// Treat all warnings as errors except deprecations
swiftc -warnings-as-errors -Wwarning deprecated MyApp.swift

// Only make API availability warnings into errors
swiftc -Werror availability MyApp.swift</code></pre><p>This feature helps teams maintain strict code quality while being pragmatic about certain warning categories. For example, you can enforce strict handling of memory management warnings while allowing time to address deprecation warnings during major version upgrades. It’s especially useful when upgrading to new Swift versions or SDK releases that introduce new deprecations.</p><h3 id="se-0444-member-import-visibility">SE-0444: Member import visibility</h3><p><em><strong>Links</strong></em>: 📝 <a href="https://github.com/swiftlang/swift-evolution/blob/main/proposals/0444-member-import-visibility.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0444-member-import-visibility/74519">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0444-member-import-visibility/74966">Acceptance</a></p><p>Did you ever notice that you could access extensions from third-party Swift packages you didn’t even import in a given Swift file? While you always needed to import a module to use its types, extensions on existing types like String were silently available through transitive imports. Here’s why that’s problematic:</p><pre><code class="language-swift">// Without importing GroceryKit, its extensions are still available
import RecipeKit
let recipe = &quot;ingredients...&quot;.parse() // Ambiguous if GroceryKit adds parse()!

// The fix: Extensions need explicit imports
import RecipeKit
let recipe = &quot;ingredients...&quot;.parse() // Unambiguous - only sees RecipeKit's parse()</code></pre><p>This proposal fixes this inconsistency in Swift’s module system by making extension methods follow the same visibility rules as types. Due to the breaking change nature (you may need a lot more imports), it will initially be available behind the <code>MemberImportVisibility</code> compiler flag before becoming the default behavior in a future Swift version.</p><h3 id="se-0445-improving-stringindexs-printed-descriptions">SE-0445: Improving <code>String.Index</code>’s printed descriptions</h3><p><em><strong>Links</strong></em>: 📝 <a href="https://github.com/swiftlang/swift-evolution/blob/main/proposals/0445-string-index-printing.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0445-improving-string-indexs-printed-descriptions/74643">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-with-modifications-se-0445-improving-string-index-s-printed-descriptions/75108">Acceptance</a></p><p>A quality-of-life improvement coming in Swift 6.1 that makes debugging string operations easier by giving <code>String.Index</code> values more meaningful descriptions:</p><pre><code class="language-swift">let text = &quot;👋🏼 Hello&quot;

// Before: Cryptic output
print(text.firstRange(of: &quot;el&quot;)!)
// Index(_rawBits: 655623)..&lt;Index(_rawBits: 852487)

// After: Clear position information
print(text.firstRange(of: &quot;el&quot;)!)
// 6[utf8]..&lt;8[utf8]</code></pre><p>This is a small but useful enhancement that will particularly benefit developers working on text processing code or debugging string-related issues.</p><h3 id="other-accepted-proposals">Other Accepted Proposals</h3><ul><li><p>SE-0441: Formalize ‘language mode’ terminology
📝 <a href="https://github.com/swiftlang/swift-evolution/blob/main/proposals/0441-formalize-language-mode-terminology.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0441-formalize-language-mode-terminology/73182">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0441-formalize-language-mode-terminology/73716">Acceptance</a></p></li><li><p>SE-0442: Allow TaskGroup’s ChildTaskResult Type To Be Inferred
📝 <a href="https://github.com/swiftlang/swift-evolution/blob/main/proposals/0442-allow-taskgroup-childtaskresult-type-to-be-inferred.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0442-allow-taskgroups-childtaskresult-type-to-be-inferred/73397">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0422-allow-taskgroups-childtaskresult-type-to-be-inferred/73747">Acceptance</a></p></li><li><p>SE-0446: Nonescapable Types
📝 <a href="https://github.com/swiftlang/swift-evolution/blob/main/proposals/0446-non-escapable.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0446-nonescapable-types/74666">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-with-modifications-se-0446-nonescapable-types/75504">Acceptance</a></p></li><li><p>SE-0447: Span: Safe Access to Contiguous Storage
📝 <a href="https://github.com/swiftlang/swift-evolution/blob/main/proposals/0447-span-access-shared-contiguous-storage.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0447-span-safe-access-to-contiguous-storage/74676">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0447-span-safe-access-to-contiguous-storage/75508">Acceptance</a></p></li><li><p>SE-0448: Regex lookbehind assertions
📝 <a href="https://github.com/swiftlang/swift-evolution/blob/main/proposals/0448-regex-lookbehind-assertions.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0448-regex-lookbehind-assertions/74672">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0448-regex-lookbehind-assertions/75111">Acceptance</a></p></li><li><p>SE-0449: Allow <code>nonisolated</code> to prevent global actor inference
📝 <a href="https://github.com/swiftlang/swift-evolution/blob/main/proposals/0449-nonisolated-for-global-actor-cutoff.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0449-allow-nonisolated-to-prevent-global-actor-inference/75116">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0449-allow-nonisolated-to-prevent-global-actor-interference/75539">Acceptance</a></p></li></ul><blockquote><p>✉️ Don’t want to miss future issues? Subscribe to the <a href="https://swiftevolution.substack.com/">newsletter</a>.</p></blockquote><h2 id="proposals-in-progress">Proposals in Progress</h2><ul><li><p>SE-0450: Package traits
📝 <a href="https://github.com/swiftlang/swift-evolution/blob/main/proposals/0450-swiftpm-package-traits.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0450-package-traits/75598">Review</a></p></li><li><p>SE-0451: Raw identifiers
📝 <a href="https://github.com/swiftlang/swift-evolution/blob/main/proposals/0451-escaped-identifiers.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0451-raw-identifiers/75602">Review</a></p></li><li><p>SE-0452: Integer Generic Parameters
📝 <a href="https://github.com/swiftlang/swift-evolution/blob/main/proposals/0452-integer-generic-parameters.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0452-integer-generic-parameters/75844">Review</a></p></li><li><p>SE-0453: Vector, a fixed-size array
📝 <a href="https://github.com/swiftlang/swift-evolution/blob/main/proposals/0453-vector.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0453-vector-a-fixed-size-array/76004">Review</a></p></li></ul><h2 id="noteworthy-active-threads">Noteworthy Active Threads</h2><ul><li><p><a href="https://forums.swift.org/t/pitch-multi-statement-if-switch-do-expressions/68443">Multi-statement if/switch/do expressions</a></p></li><li><p><a href="https://forums.swift.org/t/add-license-information-to-swift-package-manager-and-expose-it-to-dependent-projects/73833">Add license info to SwiftPM &amp; expose to projects</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-language-mode-compiler-condition/73963">Language Mode Compiler Condition</a></p></li><li><p><a href="https://forums.swift.org/t/custom-coding-path-for-codable-with-swift-macro/74521">Custom Coding Path for Codable with Swift Macro</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-improved-error-handling-in-unstructured-task-initializers/74826">Improved error handling in unstructured Task initializers</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-proposal-for-enhanced-enum-pattern-matching-syntax-in-swift/75007">Proposal for Enhanced Enum Pattern Matching Syntax in Swift</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-introducing-do-let-catch-for-cleaner-error-handling/75348">Introducing do-let-catch for Cleaner Error Handling</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-revisiting-backtick-delimited-identifiers-that-allow-more-non-identifier-characters/74432">Backtick-delimited identifiers that allow more characters</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-modify-and-read-accessors/75627">Modify and read accessors</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-task-naming-api/76115">Task Naming API</a></p></li></ul><h2 id="other-news">Other News</h2><p>Before wrapping up, I want to highlight <a href="https://forums.swift.org/t/proposal-monitor-i-built-us-an-app/71107"><strong>Proposal Monitor</strong></a> by Victor Martins—a perfect companion for anyone wanting to dive deeper into Swift Evolution. While this newsletter keeps you informed about key developments, Proposal Monitor is ideal if you want to track every proposal, stay up-to-date with push notifications, or give timely feedback during review periods. <a href="https://apps.apple.com/us/app/proposal-monitor/id6449445305">Available on iOS, iPadOS, and visionOS</a>, it’s a fantastic tool for following Swift’s evolution more closely.</p>]]></content:encoded>
<media:thumbnail url="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-may-november-2024/hero.webp"/>
</item>
<item>
<title>Swift Evolution Monthly: February-April 2024</title>
<link>https://evolutionkit.dev/blog/swift-evolution-monthly-february-april-2024/</link>
<guid isPermaLink="true">https://evolutionkit.dev/blog/swift-evolution-monthly-february-april-2024/</guid>
<pubDate>Sat, 04 May 2024 00:00:00 +0000</pubDate>
<description><![CDATA[Swift 6 around the corner, Swift Backtrace APIs for improved Debugging, Improving Concurrency, a new Swift Steering Workgroup, and much more. Summarizing the best of Swift Evolution from February to April 2024.]]></description>
<content:encoded><![CDATA[<p><img src="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-february-april-2024/hero.webp" alt="Swift Evolution Monthly: February-April 2024" /></p><p>WWDC24 is just a month away and there are 2 ways I’ll be involved: Firstly, I’ll be in the area for the whole week and join all community events I can! Paul Hudsons <a href="https://www.youtube.com/watch?v=SneL19Jp1iE">great video</a> about his experience in 2023 convinced me that it’s worth it even if you didn’t get the golden ticket for Apple Park. Maybe we’ll meet there?</p><p>Secondly, I’m working on a complete overhaul of the <a href="https://wwdcnotes.com/">WWDC Notes</a> community project that I <a href="https://www.fline.dev/taking-over-wwdc-notes-and-its-future/">took over</a> last year. If you don’t know, it’s a place where members of our community share their WWDC session notes for other members in the community. This work is needed because only the notes are public, most of the projects repos (website, etc.) are not. Writing the notes is also annoying, because the website renderer doesn’t support all Markdown features and you have no way to preview them locally. My plan is to fix both issues by migrating the project over to <a href="https://www.swift.org/documentation/docc/">Swift-DocC</a>. This will allow you to preview the rendering right within Xcode!</p><p>Speaking of tools I develop for the community, I just shipped <a href="https://iosdev.space/@Jeehut/112299996029767981">a free tool</a> that helps you manage your localizations more efficiently and finds bugs. Give it a try!</p><p>Moving on to Swift Evolution News – it’s <a href="https://forums.swift.org/t/swift-6-0-release-process/70220">official now</a>, Swift 6 is coming this year at WWDC! Several of the accepted proposals I link to below have their state marked as “Implemented for Swift 6”. You’ll notice by the proposals currently being worked, that the main focus is ironing out rough edges of Swift Concurrency before the release of Swift 6, which will introduce a couple of extra safety checks.</p><p>If the release of a major new Swift version with breaking changes concerns you, Holly Borla from the Swift Core team is here put you at ease. In <a href="https://hachyderm.io/@holly/111937796779006395">this post</a>, she makes clear that the Swift 6 compiler will default to a Swift 5 compatibility mode, not breaking any of your code or your packages code. Only if you explicitly opt-in to Swift 6 mode, which you can do module by module, you’ll get the new safety checks, warnings, and errors. This means you can adopt Swift 6 at your own pace!</p><h2 id="accepted-proposal-summaries">Accepted Proposal Summaries</h2><h3 id="se-0419-swift-backtrace-api">SE-0419: Swift Backtrace API</h3><p><em><strong>Links</strong></em>: 📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0419-backtrace-api.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0419-swift-backtracing-api/69595">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-with-modifications-se-0419-swift-backtracing-api/70318">Acceptance</a></p><p>On a first look, this proposal reads like one could build a crash reporting tool based on a new <code>SymbolicatedBacktrace</code> struct it introduces. But then it states this:</p><blockquote><p><strong>(…) the API presented here is not async-signal-safe</strong>, and <strong>it is not an appropriate tool with which to build a general purpose crash reporter</strong>. The intended use case for this functionality is the programmatic capture of backtraces during normal execution.</p></blockquote><p>While backtracing and symbolication sound complex, usage can be as simple as:</p><pre><code class="language-Swift">import Runtime

enum SomeNamespace {
  static func doSomething() {
    do {
      try somethingThatCanFail()
    } catch {
      let bt = Backtrace.capture().symbolicated()
      if let sl = bt.frames[0].symbolInfo?.sourceLocation {
        print(&quot;Called from file \(sl.path) at line \(sl.line)&quot;)
      }
    }
  }
}</code></pre><p>Note that you need to <code>import Runtime</code> to use the new backtracing capabilities. As you can see in the code above, it’s easy to access the file and line of the current execution context. Think of <code>frames</code> like the left sidebar showing the whole call stack when you run into a breakpoint or your app crashes during debugging.</p><p>With Swift Backtrace APIs, things like debugging and performance analysis can be hugely improved because they make it much easier to diagnose our code. In complex applications, capturing a backtrace at the point of error or exception can even help us trace issues without halting the application. I can also imagine this to be super helpful for debugging &amp; error handling for Swift on Server.</p><h3 id="se-0421-generalize-effect-polymorphism-for-asyncsequence-and-asynciteratorprotocol">SE-0421: Generalize effect polymorphism for <code>AsyncSequence</code> and <code>AsyncIteratorProtocol</code></h3><p><em><strong>Links</strong></em>: 📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0421-generalize-async-sequence.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0421-generalize-effect-polymorphism-for-asyncsequence-and-asynciteratorprotocol/69662">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0421-generalize-effect-polymorphism-for-asyncsequence-and-asynciteratorprotocol/69973">Acceptance</a></p><p>Not being a compiler expert, I don’t fully understand this proposal. It reads similarly abstract like the title makes it sound. But I understand that there were serious problems with <code>AsyncSequence</code> regarding error handling (<code>throws</code>) and <code>Sendable</code> conformance. And this proposal introduces an associated <code>Failure</code> type and adopts my all-time favorite proposal <a href="https://www.fline.dev/swift-evolution-monthly-december-23/#se-0413-typed-throws">SE-0413 Typed Throws</a> to fix those issues, including for <code>AsyncIteratorProtocol</code> with a <code>next()</code> overload.</p><p>I think all us app developers really need to take away from this (and other accepted proposals in the recent past I didn’t cover in detail) is that Apple is really focusing on getting concurrent code in Swift to a much better place with Swift 6. I’m curious to see what new consumer features or developer APIs all this work leads up to. Maybe we’ll know more next month after WWDC24? Let’s see!</p><h3 id="se-0428-resolve-distributedactor-protocols">SE-0428: Resolve DistributedActor protocols</h3><p><em><strong>Links</strong></em>: 📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0428-resolve-distributed-actor-protocols.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0428-resolve-distributedactor-protocols/70669">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-with-modifications-se-0428-resolve-distributedactor-protocols/71366">Acceptance</a></p><p>It’s really hard to grasp the future impact of distributed actors in Swift, partly because the topic is inherently complicated, and partly because things are still in the works and practical usage examples are scarce. But certainly this proposal brings us another step closer to a future where if you control your own server, you might be able to get rid of the API layer entirely and just let the distributed actor system figure the communication details out for your client-server application.</p><p>Having that said, it’s still not clear if this is the intended use case within Apple. I’m sure there are products or services that will profit from the work in this area, but I still struggle with a clear picture. The only things that come to my mind are uses where (part of) the processing happens on non-integrated parts. Such as the Vision Pro doing part of the processing in the battery pack in a future iteration. Or Siri processing parts of a request in the Cloud. I’m really curious to see what the future brings. I have a feeling that distributed actors might play a big role at some point.</p><h3 id="se-0433-synchronous-mutual-exclusion-lock">SE-0433: Synchronous Mutual Exclusion Lock</h3><p><em><strong>Links</strong></em>: 📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0433-mutex.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0433-synchronous-mutual-exclusion-lock/71174">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0433-synchronous-mutual-exclusion-lock/71463">Acceptance</a></p><p>When we have shared mutable state in our apps and want to avoid race conditions that could lead to inconsistent state or unexpected results, our go-to solution in Swift should be using <a href="https://www.hackingwithswift.com/quick-start/concurrency/what-is-an-actor-and-why-does-swift-have-them">Actors</a>. But actors have their own requirements, and sometimes it’s not possible or reasonable to use them. In those cases…</p><blockquote><p>Many Swift programs opt to use ad-hoc implementations of a mutual exclusion lock, or a mutex. (…) The main issue is that there isn’t a single standardized implementation for this synchronization primitive resulting in everyone needing to roll their own.</p></blockquote><p>So this proposal does exactly that, it introduces an “official” Swift <code>Mutex</code> type. You need to <code>import Synchronization</code> to use it. Then, you can write something like:</p><pre><code class="language-Swift">let imageCache = Mutex&lt;[UUID: Data]&gt;([:])</code></pre><p>Now, whenever you want to write to the dictionary, you call <code>.withLock</code> like this:</p><pre><code class="language-Swift">imageCache.withLock { dict in
  dict[UUID()] = Data()
}</code></pre><p>Note that a <code>Mutex</code> cannot be defined as <code>var</code>, only <code>let</code> works for safety reasons. Besides <code>.withLock</code>, there’s also <code>withLockIfAvailable</code> which returns <code>nil</code> if the lock couldn’t be acquired. Please be aware that a <code>Mutex</code> works very differently from an <code>Actor</code> and therefore is prone to classic problems like <a href="https://en.wikipedia.org/wiki/Deadlock">deadlocks</a>. But if you know what you’re doing and you need a mutex, Swift will have you covered.</p><h2 id="other-accepted-proposals">Other Accepted Proposals</h2><ul><li><p>SE-0414: Region based Isolation
📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0414-region-based-isolation.md">Proposal</a>  |  💬 Reviews: <a href="https://forums.swift.org/t/se-0414-region-based-isolation/68805">1st</a>, <a href="https://forums.swift.org/t/se-0414-second-review-region-based-isolation/69740">2nd</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-with-modifications-se-0414-region-based-isolation/70051">Acceptance</a></p></li><li><p>SE-0422: Expression macro as caller-side default argument
📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0422-caller-side-default-argument-macro-expression.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0422-expression-macro-as-caller-side-default-argument/69730">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0422-expression-macro-as-caller-side-default-argument/70050">Acceptance</a></p></li><li><p>SE-0424: Custom isolation checking for SerialExecutor
📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0424-custom-isolation-checking-for-serialexecutor.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0424-custom-isolation-checking-for-serialexecutor/70195">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0424-custom-isolation-checking-for-serialexecutor/70480">Acceptance</a></p></li><li><p>SE-0425: 128-bit Integer Types
📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0425-int128.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0425-128-bit-integer-types/70456">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted/71063">Acceptance</a></p></li><li><p>SE-0426: BitwiseCopyable
📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0426-bitwise-copyable.md">Proposal</a>  |  💬 Reviews: <a href="https://forums.swift.org/t/se-0426-bitwisecopyable/70479">1st</a>, <a href="https://forums.swift.org/t/se-0426-second-review-bitwisecopyable/71316">2nd</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0426-bitwisecopyable/71600">Acceptance</a></p></li><li><p>SE-0429: Partial consumption of noncopyable values
📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0429-partial-consumption.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0429-partial-consumption-of-noncopyable-values/70675">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0429-partial-consumption-of-noncopyable-values/70972">Acceptance</a></p></li></ul><blockquote><p>✉️ Don’t want to miss future issues? Subscribe to the <a href="https://swiftevolution.substack.com/">newsletter</a>.</p></blockquote><h2 id="proposals-in-progress">Proposals in Progress</h2><ul><li><p>SE-0403: Package Manager Mixed Language Target Support
📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0403-swiftpm-mixed-language-targets.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/66202">Review</a>  |  🔄 <a href="https://forums.swift.org/t/66975">Returned</a></p></li><li><p>SE-0406: Backpressure support for AsyncStream
📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0406-async-stream-backpressure.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0406-backpressure-support-for-asyncstream/66771">Review</a>  |  🔄 <a href="https://forums.swift.org/t/returned-for-revision-se-0406-backpressure-support-for-asyncstream/67248">Returned</a></p></li><li><p>SE-0415: Function Body Macros
📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0415-function-body-macros.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0415-function-body-macros/68847">Review</a>  |  🔄 <a href="https://forums.swift.org/t/returned-for-revision-se-0415-function-body-macros/69114">Returned</a></p></li><li><p>SE-0423: Dynamic actor isolation enforcement from non-strict-concurrency contexts
📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0423-dynamic-actor-isolation.md">Proposal</a>  |  💬 Reviews: <a href="https://forums.swift.org/t/se-0423-dynamic-actor-isolation-enforcement-from-non-strict-concurrency-contexts/70155">1st</a>, <a href="https://forums.swift.org/t/se-0423-second-review-dynamic-actor-isolation-enforcement-from-non-strict-concurrency-contexts/71159">2nd</a></p></li><li><p>SE-0427: Noncopyable Generics
📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0427-noncopyable-generics.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0427-noncopyable-generics/70525">Review</a></p></li><li><p>SE-0430: <code>transferring</code> isolation regions of parameter and result values
📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0430-transferring-parameters-and-results.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0430-transferring-isolation-regions-of-parameter-and-result-values/70830">Review</a>  |  🔄 <a href="https://forums.swift.org/t/returned-for-revision-se-0430-transferring-isolation-regions-of-parameter-and-result-values/71297">Returned</a></p></li><li><p>SE-0431: <code>@isolated(any)</code> Function Types
📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0431-isolated-any-functions.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0431-isolated-any-function-types/70939">Review</a></p></li><li><p>SE-0432: Borrowing and consuming pattern matching for noncopyable types
📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0432-noncopyable-switch.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0432-borrowing-and-consuming-pattern-matching-for-noncopyable-types/71158">Review</a></p></li><li><p>SE-0434: Usability of global-actor-isolated types
📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0434-global-actor-isolated-types-usability.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0434-usability-of-global-actor-isolated-types/71187">Review</a></p></li><li><p>SE-0435: Swift Language Version Per Target
📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0435-swiftpm-per-target-swift-language-version-setting.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0435-swift-language-version-per-target/71546">Review</a></p></li></ul><h2 id="noteworthy-active-threads">Noteworthy Active Threads</h2><ul><li><p><a href="https://forums.swift.org/t/calling-through-original-implementations-of-autogenerated-methods/71001">Calling through original implementations of autogenerated methods</a></p></li><li><p><a href="https://forums.swift.org/t/why-do-we-prohibit-redundant-declarations-of-conformance-to-a-protocol/70882">Why prohibit redundant declarations of conformance to a protocol?</a></p></li><li><p><a href="https://forums.swift.org/t/default-parameters-for-getters-setters-friends/69965">Default parameters for getters / setters &amp; friends</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-3-objective-c-implementations-in-swift/71315">Objective-C implementations in Swift</a></p></li><li><p><a href="https://forums.swift.org/t/isolated-any-function-types/70562"><code>@isolated(any)</code> function types</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-fixing-member-import-visibility/71432">Fixing member import visibility</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-optional-orthrow/69995">Optional.orThrow</a></p></li><li><p><a href="https://forums.swift.org/t/memory-optimal-collections-of-optionals/70237">Memory-optimal collections of Optionals</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-noncopyable-standard-library-primitives/71566">Noncopyable Standard Library Primitives</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-piecewise-consumption-of-noncopyable-values/70045">Piecewise consumption of noncopyable values</a></p></li></ul><h2 id="other-news">Other News</h2><p>On the organizational front, the Core Team has <a href="https://forums.swift.org/t/platform-steering-group/71014">announced</a> the formation of a “Platform Steering Group”. According to <a href="https://www.swift.org/platform-steering-group/">its page</a> on Swift.org their goals are to “enable the Swift language and its tools to be used in new environments” and to “drive development work that brings the Swift (…) to a variety of platforms”.</p><p>And finally, don’t forget to try the 2.0 release of <a href="https://translatekit.app/">TranslateKit</a> to find common bugs in your localizations. Such as <code>%lld of %lld</code> which should be <code>%1$lld of %2$lld</code>. Or a missing <code>%@</code> in translations. And many more – all for free!</p>]]></content:encoded>
<media:thumbnail url="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-february-april-2024/hero.webp"/>
</item>
<item>
<title>Swift Evolution Monthly: January &apos;24</title>
<link>https://evolutionkit.dev/blog/swift-evolution-monthly-january-24/</link>
<guid isPermaLink="true">https://evolutionkit.dev/blog/swift-evolution-monthly-january-24/</guid>
<pubDate>Fri, 09 Feb 2024 00:00:00 +0000</pubDate>
<description><![CDATA[Smoothing out some rough edges in Swift concurrency. System-level programming with low-level atomics. And many interesting new proposals linked!]]></description>
<content:encoded><![CDATA[<p><img src="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-january-24/hero.webp" alt="Swift Evolution Monthly: January '24" /></p><p>Thanks to <a href="https://www.avanderlee.com/about/">Antoine</a>’s idea to point to other related newsletters upon subscribing, the number of people receiving this issue more than doubled within the last month, so hello and welcome on board to everyone new! 👋</p><p>January was also quite a busy month for me personally. Just as a mini recap, I shipped a <em>huge</em> 2.0 update to my puzzling game <a href="https://apps.apple.com/app/apple-store/id6472669260?pt=549314&ct=SwiftEvolutionM&mt=8">CrossCraft</a> and I released a new developer app – <a href="https://translatekit.app/">TranslateKit</a> – after weeks of frustration due to nonsensical rejections by the Review team. 😩 I’d love you to give both a try! The latter even <a href="https://www.producthunt.com/posts/string-catalog-translator">launched on Product Hunt</a> today. 👀</p><p>Note that I migrated CrossCraft to visionOS for day 1 of the Apple Vision Pro and even live-streamed the entire process <a href="https://www.twitch.tv/Jeehut">here</a>. I will upload a shorter video <a href="https://www.youtube.com/c/FlineDev">there</a>. Speaking of the Vision Pro, I also released <a href="https://apps.apple.com/app/apple-store/id6477408765?pt=549314&ct=SwiftEvolutionM&mt=8">another app</a> which I specifically developed for it to <a href="https://x.com/Jeehut/status/1755155055341179266?s=20">fix a flaw</a> in the visionOS user interface. 🕓🔋</p><p>On other news, the <a href="https://www.swift.org/">swift.org website</a> underwent a redesign. I really like how the crowded sidebar was replaced with a more organized top bar! Good job. 👏</p><h2 id="accepted-proposal-summaries">Accepted Proposal Summaries</h2><h3 id="se-0410-low-level-atomic-operations">SE-0410: Low-Level Atomic Operations</h3><p><em><strong>Links</strong></em>:📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0410-atomics.md">Proposal</a>  |  💬 Reviews: <a href="https://forums.swift.org/t/se-0410-atomics/68007">1st</a>, <a href="https://forums.swift.org/t/second-review-se-0410-atomics/68810">2nd</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-with-modifications-se-0410-atomics/69244">Acceptance</a></p><p>This introduces low-level synchronization primitives hidden behind a module named <code>Synchronization</code> that you need to explicitly import to use them. App developers should probably stick to the recently introduced concurrency features like <code>async/await</code>, but for Swift to be successful as a systems programming language, new low-level APIs like the <code>Atomic</code> type introduced here are important. Some libraries also might use it internally.</p><h3 id="se-0416-subtyping-for-keypath-literals-as-functions">SE-0416: Subtyping for keypath literals as functions</h3><p><em><strong>Links</strong></em>:📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0416-keypath-function-subtyping.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0416-subtyping-for-keypath-literals-as-functions/68984">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0416-subtyping-for-keypath-literals-as-functions/69241">Acceptance</a></p><p>This small proposal allows using key paths in some situations that were previously impossible. For example, the compiler is currently not able to convert the <code>Int</code> to an <code>Int?</code> (like it can in other contexts) in following code:</p><pre><code class="language-Swift">struct Person {
  var age: Int
}

// error: Key path value type 'Int' cannot be converted to contextual type 'Int?'
let x: (Person) -&gt; Int? = \.age</code></pre><p>In the future, key paths will work in more situations, including the above.</p><h3 id="se-0417-task-executor-preference">SE-0417: Task Executor Preference</h3><p><em><strong>Links</strong></em>:📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0417-task-executor-preference.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0417-task-executor-preference/68958">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0417-task-executor-preference/69705">Acceptance</a></a></p><p>This proposal is mostly for improving the performance on event-loop based systems like network servers. It introduces a new flexible mechanism for developers to tune their applications and avoid potentially unnecessary context switching when using Swift concurrency. Read the full proposal if this affects you. Most app developers probably are good with the current defaults.</p><h3 id="se-0418-inferring-sendable-for-methods-and-key-path-literals">SE-0418: Inferring Sendable for methods and key path literals</h3><p>📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0418-inferring-sendable-for-methods.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0418-inferring-sendable-for-methods-and-key-path-literals/68999">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0418-inferring-sendable-for-methods-and-key-path-literals/69242">Acceptance</a></a></p><p>This one improves flexibility, simplicity, and ergonomics in some edge cases by inferring <code>@Sendable</code> in more situations surrounding functions as values and key path literals. As a quick reminder, the <code>Sendable</code> protocol indicates that a type is safe to be passed to other Tasks and Actors in Swift concurrency. You’ve probably already seen warnings in some places when using <code>async/await</code>. In Swift 6, some (or all?) of those warnings will become compiler errors, so it’s good news that Sendability is inferred in more situations to reduce friction when entering the world of more strict safety.</p><h3 id="se-0420-inheritance-of-actor-isolation">SE-0420: Inheritance of actor isolation</h3><p>📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0420-inheritance-of-actor-isolation.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0420-inheritance-of-actor-isolation/69638">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0420-inheritance-of-actor-isolation/69913">Acceptance</a></a></p><p>Here’s another change that will reduce the friction around <code>Sendable</code> types in Swift 6. The purpose of this proposal is to allow non-<code>Sendable</code> data to be safely passed to functions by inheriting the isolation context. An <code>isolated</code> keyword (introduced in <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0313-actor-isolation-control.md#actor-isolated-parameters">SE-0313</a>) can be put in front of actor types alongside an <code>#isolation</code> expression as a default value to achieve that. As a result, functions might get declared like this:</p><pre><code class="language-Swift">func foo(isolation: (any Actor)? = #isolation) async</code></pre><p>If you want to learn more about the <code>isolated</code> keyword, the same Antoine I mentioned at the beginning has written <a href="https://www.avanderlee.com/swift/nonisolated-isolated/">a great article</a> about it.</p><p>All in all, I really like the continued effort in Swift to make concurrency work more smoothly in more situations. I have a feeling that Swift 6 isn’t too far off anymore, given that we are seeing more edge cases being tackled. Maybe later this year? 🤞</p><blockquote><p>✉️ Don’t want to miss future issues? Subscribe to the <a href="https://swiftevolution.substack.com/">newsletter</a> for free.</p></blockquote><h2 id="proposals-in-progress">Proposals in Progress</h2><ul><li><p>SE-0403: Package Manager Mixed Language Target Support<br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0403-swiftpm-mixed-language-targets.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/66202">Review</a>  |  🔄 <a href="https://forums.swift.org/t/66975">Returned</a></p></li><li><p>SE-0406: Backpressure support for AsyncStream<br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0406-async-stream-backpressure.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0406-backpressure-support-for-asyncstream/66771">Review</a>  |  🔄 <a href="https://forums.swift.org/t/returned-for-revision-se-0406-backpressure-support-for-asyncstream/67248">Returned</a></p></li><li><p>SE-0414: Region based Isolation<br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0414-region-based-isolation.md">Proposal</a>  |  💬 Reviews: <a href="https://forums.swift.org/t/se-0414-region-based-isolation/68805">1st</a>, <a href="https://forums.swift.org/t/se-0414-second-review-region-based-isolation/69740">2nd</a></p></li><li><p>SE-0415: Function Body Macros<br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0415-function-body-macros.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0415-function-body-macros/68847">Review</a>  |  🔄 <a href="https://forums.swift.org/t/returned-for-revision-se-0415-function-body-macros/69114">Returned</a></p></li><li><p>SE-0416: Subtyping for keypath literals as functions<br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0416-keypath-function-subtyping.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0416-subtyping-for-keypath-literals-as-functions/68984">Review</a> |  🔄 <a href="https://forums.swift.org/t/returned-for-revision-se-0415-function-body-macros/69114">Returned</a></p></li><li><p>SE-0419: Swift Backtracing API<br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0419-backtrace-api.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0419-swift-backtracing-api/69595">Review</a></p></li><li><p>SE-0421: Generalize effect polymorphism for AsyncSequence &amp; AsyncIteratorProtocol<br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0421-generalize-async-sequence.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0421-generalize-effect-polymorphism-for-asyncsequence-and-asynciteratorprotocol/69662">Review</a></p></li><li><p>SE-0422: Expression macro as caller-side default argument<br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0422-caller-side-default-argument-macro-expression.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0422-expression-macro-as-caller-side-default-argument/69730">Review</a></p></li></ul><h2 id="noteworthy-active-threads">Noteworthy Active Threads</h2><ul><li><p><a href="https://forums.swift.org/t/pitch-resolve-distributedactor-protocols-for-server-client-apps/69933">Resolve DistributedActor protocols (for server/client apps)</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-default-values-for-string-interpolations/69381">Default values for string interpolations</a></p></li><li><p><a href="https://forums.swift.org/t/future-of-codable-and-json-coders-in-swift-6-hoping-for-a-rework/69542">Future of Codable and JSON-Coders in Swift 6: Hoping for a rework</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-unicode-processing-apis/69294">Unicode Processing APIs</a></p></li><li><p><a href="https://forums.swift.org/t/async-support-in-defer-blocks/69455">Async support in defer blocks?</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-non-escapable-types-and-lifetime-dependency/69865">Non-Escapable Types and Lifetime Dependency</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-synchronous-mutual-exclusion-lock/69889">Synchronous Mutual Exclusion Lock</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-enable-bounds-checking-for-bufferpointers/69733">Enable bounds-checking for BufferPointers</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-safe-access-to-contiguous-storage/69888">Safe Access to Contiguous Storage</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-2-low-level-linkage-control/69752">Low-level linkage control</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-low-level-operations-for-volatile-memory-accesses/69483">Low-level operations for volatile memory accesses</a></p></li></ul><p>I love how Swift is becoming more widely usable, which I’m sure will make it a better language for app developers, too.</p><p>I’m also particularly excited about the first link in the “Active Threads” section. If I understood it correctly on a quick read, it has the potential to make away with the need to write API clients for servers altogether, hiding the client-server communication in a distributed actor. Check it out!</p><p>That was it for January. Don’t forget to try <a href="https://apps.apple.com/app/apple-store/id6472669260?pt=549314&ct=swiftevolution.substack.com&mt=8">CrossCraft</a> &amp; <a href="https://translatekit.app/">TranslateKit</a>! 🌟🙏</p>]]></content:encoded>
<media:thumbnail url="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-january-24/hero.webp"/>
</item>
<item>
<title>Swift Evolution Monthly: December &apos;23</title>
<link>https://evolutionkit.dev/blog/swift-evolution-monthly-december-23/</link>
<guid isPermaLink="true">https://evolutionkit.dev/blog/swift-evolution-monthly-december-23/</guid>
<pubDate>Mon, 25 Dec 2023 00:00:00 +0000</pubDate>
<description><![CDATA[Our biggest wish came true: Explaining Typed Throws in Swift. Also: Improved namespacing and reduced dependency creep. And 14 more proposals linked!]]></description>
<content:encoded><![CDATA[<p><img src="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-december-23/hero.webp" alt="Swift Evolution Monthly: December '23" /></p><p>Back when there was no Swift on Server, I used to develop my backends with <a href="https://rubyonrails.org/">Ruby on Rails</a>. And I remember how the Ruby team tried to time their major releases for Christmas which made it feel a bit like a gift from Santa. Now I feel like the Swift team has managed to do the same this year – their gift is the acceptance of  <strong>Typed Throws</strong> into the Swift language! 🎁 Yes, it’s really coming. 😍🎉</p><p>But before I get to the proposals, I want to mention 2 things:</p><p>You might have noticed that there have been no issues of this newsletter since July. That’s simply because I decided that I would no longer attempt to summarize every single proposal. Instead, I’ll focus on those that are most interesting to app developers like myself. My summaries for the more low-level or the advanced server-only topics weren’t very useful anyway. But I will still link to them for those interested!</p><p>Speaking of app development, you could make me a little gift by checking out my newest Indie app creation – it’s an app to craft themed &amp; personalized crossword puzzles. You’re not a fan of crosswords? But you might still be interested in a fun challenge about a topic you like, such as Swift/iOS Development, Technology, or one of the other 20 topics in various categories. Test your knowledge or prepare a special gift for your loved ones. Try it now &amp; rate it to support me. Thanks! 🙏 👇</p><p><a href="https://apps.apple.com/app/apple-store/id6472669260?pt=549314&ct=swiftevolution.substack.com&mt=8">‎CrossCraft: Custom Crosswords</a></p><p><em>Creating, playing, and sharing crossword puzzles is free!</em></p><h2 id="accepted-proposal-summaries">Accepted Proposal Summaries</h2><h3 id="se-0413-typed-throws">SE-0413: Typed throws</h3><p><em><strong>Links</strong></em>:📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0413-typed-throws.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0413-typed-throws/68507">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0387-swift-sdks-for-cross-compilation/66399https://forums.swift.org/t/accepted-se-0413-typed-throws/69099">Acceptance</a></p><p>This is probably the most requested Swift feature in recent years. Many have asked for it, but some rejected it, too. Here’s what it’s all about:</p><p>Imagine you use a function you didn’t write yourself (or wrote years ago) that is throwing, such as <code>func parseCSVFile(at url: URL) throw -&gt; [Entry]</code>. Let’s say the function throws in 3 different cases:</p><ol><li><p>When no file exists at the given path</p></li><li><p>When the app has no access to the path (Sandbox)</p></li><li><p>When the contents of the file have an invalid format</p></li></ol><p>Unless those 3 cases are documented on the function (which even Apple doesn’t do on most system APIs), you can’t easily know or handle them separately for a custom-tailored experience. You’d have to read through the full implementation of the function and all throwing functions the function calls inside. A time-consuming and error-prone task. Sometimes you don’t even have access to the implementation.</p><p>For example, if no file exists at the provided path, you might want to traverse all files in the folder and see if you can find a similarly named file, e.g. using a <a href="https://en.wikipedia.org/wiki/Levenshtein_distance">Levenshtein distance</a> of 2 or lower. If you find a similar one, you could ask the user if they meant that file instead. Depending on your use case, this might be a welcome improvement over just showing a generic error message, which just delegates error handling to the user.</p><p>With typed throws in Swift, the author of the <code>parseCSVFile</code> function will have the option to explicitly specify the possible throwing cases. Typically, an <code>enum</code> type is created to represent the possible cases like so:</p><pre><code class="language-Swift">enum CSVParsingError: Error {
   case noFileFound(url: URL)
   case noAccessToPath(url: URL)
   case invalidContentFormat(line: Int?)
}</code></pre><p>These types often exist already for many throwing functions. However, the function declaration doesn’t contain information about the type yet. Now it can:</p><pre><code class="language-Swift">func parseCSVFile(at url: URL) throws(CSVParsingError) -&gt; [Entry]</code></pre><p>The only option API authors had until now to make the error type explicit was to return <code>Result&lt;[Entry], CSVParsingError&gt;</code> instead, which will no longer be needed. To handle each error case separately, you can then switch-case over the possible errors in the <code>catch</code> block like so:</p><pre><code class="language-Swift">do {
   let entries = try parseCSVFile(at: userProvidedURL)
   // ...
} catch {
   switch error {
   case .noFileFound: // try to find similarly named ones
   case .noAccessToPath: // show UI to fix Sandbox access
   case .invalidContentFormat: // ask user: skip line or cancel
   }
}</code></pre><p><em>The <code>error</code> in the <code>catch</code> block is of type <code>CSVParsingError</code>, not <code>any Error</code>!</em></p><p>This is a huge improvement, as you know exactly what can fail and can react to each case differently, as I hinted at in the comments. Not only that, you also don’t have a <code>default</code> case, so if you wanted to handle each error with a special UI, you can. No need for a generic text message UI at all, which you always would have needed with untyped errors, cause there could always be an error you missed or that gets added later on. With typed throws, the compiler ensures you handle all cases and fails at compile-time if you don’t, even if new cases got added to the function.</p><p>Does that mean we can expect all future Apple system APIs to have a documented error type, exposing all possible error cases? No, unfortunately not. This has technical reasons: Apple ships new versions of their operating systems regularly, changing APIs all the time. Users expect apps to run on newer OS versions without the need for us to resubmit our apps. If Apple added a new error case to the above enum, like <code>providedPathIsAFolder</code> all apps that use a <code>switch-case</code> would have undefined behavior if that new error occurred. Therefore only those few functions where the error cases are clear forever by the functions nature can adopt typed throws on the system level. Those are probably rare.</p><p>But 3rd-party developers are much more flexible as their frameworks are updated and recompiled by the app developer in Xcode, not by the user via a system update. If they specify the error type explicitly, they simply make the errors part of their public API, therefore changes to the errors would break the API. With proper versioning, this is not a problem – which doesn’t mean that <em>all</em> functions should adopt typed throws. Some probably still shouldn’t. But they have a choice now. And app developers should be able to use typed throws for their project-internal functions without issues.</p><p>To <strong>not</strong> specify an error type, continue to specify your functions as <code>throws</code> without a type, in which case the old <code>any Error</code> behavior remains – a <code>throws</code> effectively is equal to <code>throws(any Error)</code>. This also means that the change is fully source-compatible and people can adopt typed throws step by step.</p><p>There are a lot more details in the proposal about things like subtyping, its relation with the <code>Result</code> type or <code>rethrows</code>, and much more. Read it to learn more!</p><h3 id="se-0404-nested-protocols-in-non-generic-contexts">SE-0404: Nested Protocols in Non-Generic Contexts</h3><p><em><strong>Links</strong></em>:📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0404-nested-protocols.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0404-allow-protocols-to-be-nested-in-non-generic-contexts/66332">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0404-allow-protocols-to-be-nested-in-non-generic-contexts/66668">Acceptance</a></a></p><p>If you have ever defined a protocol type that is closely related to another type, you might have wanted to define the protocol directly inside the type. This has two advantages: It namespaces it to make the connection clear, and when using it inside the type, its name is much shorter and to the point. But protocols had to be defined globally until now. Not anymore – in the future they can be placed in non-generic contexts like classes, structs, or enums. For example, this allows Apple to move protocols like <code>UITableViewDelegate</code> into related namespaces as follows:</p><pre><code class="language-Swift">extension UITableView {
   protocol Delegate {
      // ...
   }
}</code></pre><p><em>To reference the protocol, you would write <code>UITableView.Delegate</code>.</em></p><p>To keep existing code compatible with the rename, they could define a typealias:</p><pre><code class="language-Swift">typealias UITableViewDelegate = UITableView.Delegate</code></pre><p>And of course, we all can use this, too! The future of Swift is going to be more namespaced, which I think can make code more readable overall. 👍</p><h3 id="se-0409-access-level-modifiers-on-import-declarations">SE-0409: Access-level modifiers on import declarations</h3><p>📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0409-access-level-on-imports.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0409-access-level-modifiers-on-import-declarations/67290">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-with-modifications-se-0409-access-level-modifiers-on-import-declarations/67666">Acceptance</a></a></p><p>This one is only important to library authors or those who modularize their apps using SwiftPM. It adds the <code>private</code>, <code>internal</code>, and <code>public</code> keywords to import statements. If you <code>private import</code> a dependency, it’s only usable in <code>private</code> or <code>fileprivate</code> declarations in the current file. If you <code>internal import</code> a dependency, you can additionally use the dependency on <code>internal</code> signatures. Only if you <code>public import</code> a dependency, you can use it additionally on <code>public</code> or <code>open</code> declarations, which is equal to the current behavior of a simple <code>import</code>.</p><p>The purpose of this proposal is to give package authors the possibility to hide implementation details. Because if there’s no <code>public import</code> of a given dependency B in your whole package, the compiler no longer has to make that dependency B available to users of your package A and can strip it. This will help limit dependency creep and will make our package ecosystem healthier as a whole.</p><p>Note that with Swift 5, if you don’t specify the access level and use a simple <code>import</code>, it will effectively be treated as a <code>public import</code>. But starting with Swift 6 this behavior will change, it will be treated as an <code>internal import</code> instead and no longer be usable in <code>public</code> declarations. Migration will be easy though, just add <code>public</code> where you get a compilation error. Xcode might even provide a fix-it. 🤞</p><blockquote><p>✉️ Don’t want to miss future issues? Subscribe to the <a href="https://swiftevolution.substack.com/">newsletter</a> for free.</p></blockquote><h2 id="other-accepted-proposals">Other Accepted Proposals</h2><ul><li><p>SE-0387: Swift SDKs for Cross-Compilation<br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0387-cross-compilation-destinations.md">Proposal</a>  |  💬 Reviews: <a href="https://forums.swift.org/t/se-0387-cross-compilation-destination-bundles/62875">1st</a>, <a href="https://forums.swift.org/t/second-review-se-0387-cross-compilation-destination-bundles/64660">2nd</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0387-swift-sdks-for-cross-compilation/66399">Acceptance</a></a></p></li><li><p>SE-0405: String Initializers with Encoding Validation<br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0405-string-validating-initializers.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0405-string-initializers-with-encoding-validation/66655">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-with-modifications-se-0405-string-initializers-with-encoding-validation/67134">Acceptance</a></a></p></li><li><p>SE-0407: Member Macro Conformances<br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0407-member-macro-conformances.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0407-member-macro-conformances/66951">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0407-member-macro-conformances/67345">Acceptance</a></a></p></li><li><p>SE-0408: Pack Iteration<br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0408-pack-iteration.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/review-se-0408-pack-iteration/67152">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0408-pack-iteration/67598">Acceptance</a></p></li></ul></a>
- SE-0411: Isolated default value expressions  
📝 [Proposal](https://github.com/apple/swift-evolution/blob/main/proposals/0411-isolated-default-values.md)  |  💬 [Review](https://forums.swift.org/t/se-0411/68065)  |  ✅ [Acceptance](https://forums.swift.org/t/accepted-se-0411-isolated-default-value-expressions/68806)</a>
- SE-0412: Strict concurrency for global variables  
📝 [Proposal](https://github.com/apple/swift-evolution/blob/main/proposals/0412-strict-concurrency-for-global-variables.md)  |  💬 [Review](https://forums.swift.org/t/se-0412-strict-concurrency-for-global-variables/68352)  |  ✅ [Acceptance](https://forums.swift.org/t/accepted-se-0412-strict-concurrency-for-global-variables/69004)
<h2 id="proposals-in-progress">Proposals in Progress</h2><ul><li><p>SE-0403: Package Manager Mixed Language Target Support<br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0403-swiftpm-mixed-language-targets.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/66202">Review</a>  |  🔄 <a href="https://forums.swift.org/t/66975">Returned</a></p></li><li><p>SE-0406: Backpressure support for AsyncStream<br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0406-async-stream-backpressure.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0406-backpressure-support-for-asyncstream/66771">Review</a>  |  🔄 <a href="https://forums.swift.org/t/returned-for-revision-se-0406-backpressure-support-for-asyncstream/67248">Returned</a></p></li><li><p>SE-0410: Low-Level Atomic Operations<br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0410-atomics.md">Proposal</a>  |  💬 Reviews: <a href="https://forums.swift.org/t/se-0410-atomics/68007">1st</a>, <a href="https://forums.swift.org/t/second-review-se-0410-atomics/68810">2nd</a></p></li><li><p>SE-0414: Region based Isolation<br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0414-region-based-isolation.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0414-region-based-isolation/68805">Review</a>  |  🔄 <a href="https://forums.swift.org/t/returned-for-revision-se-0414-region-based-isolation/69123">Returned</a></p></li><li><p>SE-0415: Function Body Macros<br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0415-function-body-macros.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0415-function-body-macros/68847">Review</a>  |  🔄 <a href="https://forums.swift.org/t/returned-for-revision-se-0415-function-body-macros/69114">Returned</a></p></li><li><p>SE-0416: Subtyping for keypath literals as functions<br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0416-keypath-function-subtyping.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0416-subtyping-for-keypath-literals-as-functions/68984">Review</a></p></li><li><p>SE-0417: Task Executor Preference<br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0417-task-executor-preference.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0417-task-executor-preference/68958">Review</a></p></li><li><p>SE-0418: Inferring <code>Sendable</code> for methods and key path literals<br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0418-inferring-sendable-for-methods.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0418-inferring-sendable-for-methods-and-key-path-literals/68999">Review</a></p></li></ul><h2 id="noteworthy-active-threads">Noteworthy Active Threads</h2><ul><li><p><a href="https://forums.swift.org/t/accepted-again-se-0220-count-where/66659">[Accepted (again)] SE-0220: count(where:)</a></p></li><li><p><a href="https://forums.swift.org/t/accepted-a-vision-for-embedded-swift/68067">[Accepted] A vision for Embedded Swift</a></p></li><li><p><a href="https://forums.swift.org/t/progress-toward-the-swift-6-language-mode/68315">Progress toward the Swift 6 language mode</a></p></li><li><p><a href="https://forums.swift.org/t/macro-adoption-concerns-around-swiftsyntax/66588">Macro Adoption Concerns around SwiftSyntax</a></p></li><li><p><a href="https://forums.swift.org/t/a-new-approach-to-testing-in-swift/67425">A New Approach to Testing in Swift</a></p></li></ul><p>And that’s it for December. Don’t forget to try my new app <a href="https://apps.apple.com/app/apple-store/id6472669260?pt=549314&ct=swiftevolution.substack.com&mt=8">CrossCraft</a>. 🧩<br />And happy holidays, everyone 🎄 ☃️ 🎆</p>]]></content:encoded>
<media:thumbnail url="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-december-23/hero.webp"/>
</item>
<item>
<title>Swift Evolution Monthly: June &apos;23</title>
<link>https://evolutionkit.dev/blog/swift-evolution-monthly-june-23/</link>
<guid isPermaLink="true">https://evolutionkit.dev/blog/swift-evolution-monthly-june-23/</guid>
<pubDate>Mon, 03 Jul 2023 00:00:00 +0000</pubDate>
<description><![CDATA[WWDC 23 Aftermath, 0 Proposals Accepted in June, Milestone: #400, 2 new Proposals & 10 Pitches linked, OpenAPI Generator.]]></description>
<content:encoded><![CDATA[<p><img src="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-june-23/hero.webp" alt="Swift Evolution Monthly: June '23" /></p><p>WWDC23 was full of hardware announcements and even brought us a new platform: visionOS. Xcode 15 and Swift 5.9 are also in beta phase now with a great set of new features. Of course, for readers of this newsletter, there were no big surprises in the “What’s New in Swift” session (except for the large focus on <a href="https://forums.swift.org/t/c-interoperability-in-swift-5-9/65369">C++ interoperability</a>). But if you didn’t have the time to check out the other sessions, including those about Swift Macros which were a focus in the last 3 issues, you might want to visit the <a href="https://wwdcnotes.com/">WWDC Notes</a> project website which has a <a href="https://wwdcnotes.com/events/wwdc23/">dedicated section</a> with notes about this year’s sessions. At the time of this writing, 75 sessions from 2023 were already covered by 25+ amazing community members, and still counting. 🎉🙏</p><p>If you don’t know where to start, I’ve prepared a thread with a ~250-character-long summary <a href="https://twoot-it.app/">twoot</a> for each of my personal Top 25 sessions. It can both help you learn some tidbits of these sessions with minimal time &amp; explore the ones you might want to dive into further by reading the full notes or watching the session:</p><p><a href="https://twitter.com/Jeehut/status/1667974311724949504">🐦 Twitter Thread</a>   |   <a href="https://iosdev.space/@Jeehut/110527231917189918">🐘 Mastodon Thread</a></p><h2 id="accepted-proposals">Accepted Proposals</h2><p>No new proposals were accepted in June. 😱 I guess that’s a consequence of 7 proposals being accepted in May to make it into the language before WWDC.</p><p>I’m also skipping the old proposal, no one seems to be using the <a href="https://github.com/FlineDev/swift-evolution">repo</a> anyway. 🤷‍♂️</p><p>But there are two new proposals in Review, so after the packed <a href="https://www.fline.dev/swift-evolution-monthly-may-23/">May issue</a> and a light June issue this time, we might get a decent July issue next month. 🤞</p><p>Worth noting that a milestone of <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0400-init-accessors.md">400 proposals</a> has been reached! 💯💯💯💯 🥳</p><h2 id="proposals-in-progress">Proposals in Progress</h2><ul><li><p><strong>SE-0385: Custom Reflection Metadata</strong><br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0385-custom-reflection-metadata.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0385-custom-reflection-metadata/62777">Review</a>  |  🔄 <a href="https://forums.swift.org/t/returned-for-revision-se-0385-custom-reflection-metadata/63758">Returned</a></p></li><li><p><strong>SE-0387: Swift SDKs for Cross-Compilation</strong><br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0387-cross-compilation-destinations.md">Proposal</a>  |  💬 Reviews: <a href="https://forums.swift.org/t/se-0387-cross-compilation-destination-bundles/62875">1st</a>, <a href="https://forums.swift.org/t/second-review-se-0387-cross-compilation-swift-sdks-previously-destination-bundles/64660">2nd</a></p></li><li><p><strong>SE-0395: Observation</strong><br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0395-observability.md">Proposal</a>  |  💬 Reviews: <a href="https://forums.swift.org/t/se-0395-observability/64342">1st</a>, <a href="https://forums.swift.org/t/second-review-se-0395-observability/65261">2nd</a></p></li><li><p><strong>SE-0400: Init Accessors</strong><br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0400-init-accessors.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0400-init-accessors/65583">Review</a></p></li><li><p><strong>SE-0401: Remove Actor Isolat. Inference caused by Prop. Wrappers</strong><br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0401-remove-property-wrapper-isolation.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0401-remove-actor-isolation-inference-caused-by-property-wrappers/65618">Review</a></p></li></ul><hr /><blockquote><p>✨ Want to see your ad here? Contact me at <a href="mailto:ads@fline.dev">ads@fline.dev</a> to get in touch.</p></blockquote><hr /><h2 id="recently-active-pitchesdiscussions">Recently Active Pitches/Discussions</h2><ul><li><p><a href="https://forums.swift.org/t/pitch-allow-protocols-to-be-nested-in-non-generic-contexts/65285">Allow Protocols to be Nested in Non-Generic Contexts</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-with-functions-in-the-standard-library/65716"><code>With</code> functions in the standard library</a></p></li><li><p><a href="https://forums.swift.org/t/guard-let-catch-and-if-let-catch-to-avoid-long-nested-do-blocks/65827">Guard-Let-Catch (and If-Let-Catch) to avoid long (nested) do-blocks</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-sequence-grouped-by-and-keyed-by/65511">Sequence grouped(by:) and keyed(by:)</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-restore-count-where-from-se-0220/65859">Restore count(where:) from SE-0220</a></p></li><li><p><a href="https://forums.swift.org/t/add-accumulator-tinyarray-to-the-standard-library/65675">Add Accumulator/TinyArray to the standard library?</a></p></li><li><p><a href="https://forums.swift.org/t/non-reentrant-actors/65888">Non-Reentrant Actors</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-generalize-conformance-macros-as-extension-macros/65653">Generalize <code>conformance</code> macros as <code>extension</code> macros</a></p></li><li><p><a href="https://forums.swift.org/t/permutablecollection-protocol/65314">PermutableCollection protocol</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-properties-and-subscripts-with-optional-getters/65536">Properties and subscripts with optional getters</a></p></li></ul><h2 id="other-developments-worth-mentioning">Other Developments Worth Mentioning</h2><p>A really cool open-source surprise at WWDC was the <a href="https://www.swift.org/blog/introducing-swift-openapi-generator/">Swift OpenAPI Generator announcement</a>. Apple dedicated a <a href="https://developer.apple.com/videos/play/wwdc2023-10171">full session</a> to it and I recommend watching it if you happen to have an app with its own server, or if you plan to add a server to your app in the future. The most amazing thing about this new set of libraries is how flexibly you can make use of them:</p><p>You were using a networking library in your app or you wrote your own networking client using <code>URLSession</code>? No more: Just <a href="https://github.com/apple/swift-openapi-urlsession">generate the client code</a>.</p><p>You were using Vapor as a server and had to map your routes and parameters to your business logic manually? No more: Just <a href="https://github.com/swift-server/swift-openapi-vapor">generate the server code</a>.</p><p>You were using complex workflows to ensure your non-Swift server and your Swift client are always in sync? No more: Just write a YAML file like any other code.</p><p><a href="https://learn.openapis.org/">OpenAPI</a> (not to mix up with OpenAI) is an industry-standard for HTTP API specs and there’s <a href="https://tools.openapis.org/">a ton of tooling</a> around the API spec that can help streamline API creation, documentation, testing, and usage – Apple’s tools are just the latest to join a big family. At the core of OpenAPI is the spec file – I recommend writing one with a GUI like <a href="https://apigit.com/">APIGit</a> so you don’t have to remember the syntax – this was the only one I found to support typed params and having a useful Free tier.</p><p>There’s also a process to influence the future direction of the project in a very similar (but more lightweight) manner to Swift Evolution itself, learn more <a href="https://swiftpackageindex.com/apple/swift-openapi-generator/0.1.3/documentation/swift-openapi-generator/proposals">here</a>.</p><p>And that’s it for June! It’s been a busy month but it was fun. 🍏🥽</p><blockquote><p>💁🏻‍♂️ <strong>Enjoyed this article? Check out TranslateKit!</strong>
A drag &amp; drop translator for String Catalog files – it’s really easy.
<a href="https://apps.apple.com/app/apple-store/id6476773066?pt=549314&ct=fline.dev&mt=8"><strong>Get it now</strong></a> to machine-translate your app to up to 150 languages!</p></blockquote>]]></content:encoded>
<media:thumbnail url="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-june-23/hero.webp"/>
</item>
<item>
<title>Swift Evolution Monthly: May &apos;23</title>
<link>https://evolutionkit.dev/blog/swift-evolution-monthly-may-23/</link>
<guid isPermaLink="true">https://evolutionkit.dev/blog/swift-evolution-monthly-may-23/</guid>
<pubDate>Sun, 04 Jun 2023 00:00:00 +0000</pubDate>
<description><![CDATA["package" Modifier, Noncopyable structs/enums, Custom Actor Executors, Freestanding Declaration Macros, more Packs.]]></description>
<content:encoded><![CDATA[<p><img src="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-may-23/hero.webp" alt="Swift Evolution Monthly: May '23" /></p><p>WWDC is rapidly approaching – and if <a href="https://www.fline.dev/swift-evolution-monthly-june-22/">last year is any sign</a>, then many of the proposals covered in past issues and down below in this one will be an integral part of the session videos: Either because Apple introduces new APIs only possible thanks to recent changes in Swift, or simply to give developers advice on how to make use of Swifts latest features. As <a href="https://github.com/twostraws/wwdc">many things</a> are going on in the community right now inspired by WWDC, I will try to keep this issue as short as possible.</p><p>I don’t want to skip these two topics though:</p><ol><li><p>The <a href="https://wwdcnotes.com/">WWDC Notes</a> project is more active than ever this year. With the help of the community, we aim to cover 80% of all sessions within the first week. Over 20 volunteers joined within a few days, and we are looking for more contributors. If you’re unable to watch many sessions, you can still help (and profit) by contributing notes for one or two sessions. Together, we can achieve a lot. Join us <a href="https://join.slack.com/t/wwdc-notes/shared_invite/zt-1wbsoo705-bydJ430uZSRILstG5GxEzg">on Slack</a> &amp; send me the topics you’re interested in to get involved!</p></li><li><p>To celebrate WWDC within my own work, I decided to add some useful and completely free features to my developer-focused app <a href="https://remafox.app/">RemafoX</a>. Also, there’s a <a href="https://www.fline.dev/remafox-wwdc-sale/">massive sale during WWDC</a> for those interested in its advanced features. I’ll leave you with a GIF demoing the new free features:</p></li></ol><p><img src="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-may-23/note-that-noncopyable.gif" alt="Note that noncopyable structs can have a deinit method, which normal structs can’t have." loading="lazy" /></p><h2 id="accepted-proposals">Accepted Proposals</h2><p>7 new proposals were accepted in May, so I’m skipping on the old one this time.</p><h3 id="se-0386-new-access-modifier-package">SE-0386: New access modifier: <code>package</code></h3><p><em><strong>Links</strong></em>:📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0386-package-access-modifier.md">Proposal</a>  |  💬 Reviews: <a href="https://forums.swift.org/t/se-0386-package-access-modifier/62808">1st</a>, <a href="https://forums.swift.org/t/second-review-se-0386-package-access-modifier/64086">2nd</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0386-package-access-modifier/64904">Acceptance</a></p><p>Currently, Swift library authors that like to split their code into separate modules have to use the <code>public</code> access modifier to make any APIs available from one (helper) module to another. This makes these APIs available to all users of the package, even if the API is not intended for public use. Library authors have to stick to a single module design to actually keep helper functions internal to the package.</p><p>Not anymore! The new access modifier <code>package</code> can be used in the future to mark any API as “internal to the package”, making it available to other modules within the same package, but not accessible to users of the package. 🎉</p><h3 id="se-0390-noncopyable-structs-and-enums">SE-0390: Noncopyable structs and enums</h3><p><em><strong>Links</strong></em>:📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0390-noncopyable-structs-and-enums.md">Proposal</a>  |  💬 Reviews: <a href="https://forums.swift.org/t/se-0390-noncopyable-structs-and-enums/63258">1st</a>, <a href="https://forums.swift.org/t/second-review-se-0390-noncopyable-structs-and-enums/63866">2nd</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0390-noncopyable-structs-and-enums/65157">Acceptance</a></p><p>In Swift, we currently have value types (like <code>struct</code>) and reference types (like <code>class</code>). We use value types to represent blobs of data that are implicitly copied when we pass them along to other functions. We use reference types whenever we don’t want this copying behavior and instead want to pass a pointer so there’s a single object that can be changed by other functions directly.</p><p>This proposal introduces a third concept that can be often used in place of a class in the future: A “noncopyable” type. You can create a struct and conform it to <code>~Copyable</code> (read: “suppress Copyable”) and when passing it along to functions, it won’t be copied implicitly. But unlike classes, there’s no overhead of storing the data in the heap (saves memory) or reference counting (saves CPU cycles).</p><p>The example provided in the proposal is a <code>FileDescriptor</code>:</p><pre><code class="language-Swift">struct FileDescriptor: ~Copyable {
  private var fd: Int32

  init(fd: Int32) { self.fd = fd }

  func write(buffer: Data) {
    buffer.withUnsafeBytes { 
      write(fd, $0.baseAddress!, $0.count)
    }
  }

  deinit {
    close(fd)
  }
}</code></pre><p><em>Note that noncopyable structs can have a <code>deinit</code> method, which normal structs can’t have.</em></p><p>There are some requirements for nested types (they need to be <code>~Copyable</code>, too) and limitations for generic types (see <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0390-noncopyable-structs-and-enums.md#working-around-the-generics-restrictions">workarounds</a>). But this sounds like it’s going to change some current Best Practices about correct and performant Swift code. Read <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0390-noncopyable-structs-and-enums.md#using-noncopyable-values">this section</a> to learn more about the usage of noncopyable types.</p><h3 id="se-0392-custom-actor-executors">SE-0392: Custom Actor Executors</h3><p><em><strong>Links</strong></em>:📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0392-custom-actor-executors.md">Proposal</a>  |  💬 Reviews: <a href="https://forums.swift.org/t/se-0392-custom-actor-executors/63599">1st</a>, <a href="https://forums.swift.org/t/second-review-se-0392-custom-actor-executors/64257">2nd</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0392-custom-actor-executors/64817">Acceptance </a></p><p>This proposal introduces the concept of custom executors and customization points in Swift Concurrency, providing developers with greater control over the execution semantics of their actors. I’m not in a position to customize executors, so I can’t provide practical implications. But the motivation section ends with this:</p><blockquote><p>Along with introducing ways to customize where code executes, this proposal also introduces ways to assert and assume the appropriate executor is used. This allows for more confidence when migrating away from other concurrency models to Swift Concurrency.</p></blockquote><h3 id="se-0396-conform-never-to-codable">SE-0396: Conform <code>Never</code> to <code>Codable</code></h3><p><em><strong>Links</strong></em>:📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0396-never-codable.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0396-conform-never-to-codable/64469">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0396-conform-never-to-codable/64848">Acceptance </a></p><p>This is probably the shortest proposal I’ve ever summarized, so let’s keep it short: The proposal suggests adding <code>Codable</code> conformance to the <code>Never</code> type in Swift. This allows encoding but throws an error for decoding attempts, addressing a limitation with generic types that involve <code>Never</code>, like <code>Either&lt;Int, Never&gt;</code>.</p><hr /><blockquote><p>✨ Want to see your ad here? Contact me at <a href="mailto:ads@fline.dev">ads@fline.dev</a> to get in touch.</p></blockquote><hr /><h3 id="se-0397-freestanding-declaration-macros">SE-0397: Freestanding Declaration Macros</h3><p><em><strong>Links</strong></em>:📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0397-freestanding-declaration-macros.md">Proposal</a>  |  💬 Reviews: <a href="https://forums.swift.org/t/se-0397-freestanding-declaration-macros/64655">1st</a>, <a href="https://forums.swift.org/t/se-0397-second-review-freestanding-declaration-macros/64997">2nd</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0397-freestanding-declaration-macros/65167">Acceptance</a>  |  🔮 <a href="https://github.com/apple/swift-evolution/blob/main/visions/macros.md">Vision</a></p><p>The proposal extends Swift’s macros to allow generating declarations, enabling use cases like generating data structures from templates or introducing warning/error directives as macros. It introduces freestanding declaration macros that use the <code>#</code> syntax and have type-checked arguments, producing zero or more declarations. For example, the <code>#warning</code> directive from <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0196-diagnostic-directives.md">SE-0196</a> can be declared as a freestanding declaration macro like so:</p><pre><code class="language-Swift">@freestanding(declaration) 
macro warning(_ message: String) = #externalMacro(module: &quot;MyMacros&quot;, type: &quot;WarningMacro&quot;)</code></pre><p>The implementation part is a bit more involved like with any other macros though.</p><h3 id="se-0398-allow-generic-types-to-abstract-over-packs">SE-0398: Allow Generic Types to Abstract Over Packs</h3><p><em><strong>Links</strong></em>:📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0398-variadic-types.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0398-allow-generic-types-to-abstract-over-packs/64661">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0398-allow-generic-types-to-abstract-over-packs/64998">Acceptance</a></p><p>This introduces the ability to use generic types to abstract over packs of types. It generalizes the concepts introduced in <a href="https://www.fline.dev/swift-evolution-monthly-mar-apr-23/#se-0393-value-and-type-parameter-packs">SE-0393</a>, which allowed generic function declarations to abstract over a variable number of types (<code>each T</code>). With this proposal, you can define generic type declarations that abstract over <em>multiple</em> types, enabling the creation of more flexible and generalized algorithms.</p><p>This allows defining functions like <code>zip</code> where the return type needs an arbitrary number of type parameters – one for each input sequence:</p><pre><code class="language-Swift">func zip&lt;each S&gt;(_ seq: repeat each S) -&gt; ZipSequence&lt;repeat each S&gt;
  where repeat each S: Sequence</code></pre><p>The return type <code>ZipSequence&lt;repeat each S&gt;</code> is what this proposal allows.</p><h3 id="se-0399-tuple-of-value-pack-expansion">SE-0399: Tuple of value pack expansion</h3><p><em><strong>Links</strong></em>:📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0399-tuple-of-value-pack-expansion.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0399-tuple-of-value-pack-expansion/65017">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0399-tuple-of-value-pack-expansion/65271">Acceptance</a></p><p>Also building upon <a href="https://www.fline.dev/swift-evolution-monthly-mar-apr-23/#se-0393-value-and-type-parameter-packs">SE-0393</a>, this one enables referencing a <em>tuple</em> value that contains a value pack inside a pack repetition pattern. Currently, there is no way to reference individual elements of a value pack within a tuple or pass them as arguments to a function. This proposal fills that gap by allowing pack repetition patterns to operate on tuple values containing value packs, providing a method to access individual value pack elements within a tuple. For example:</p><pre><code class="language-Swift">func tuplify&lt;each T&gt;(_ value: repeat each T) -&gt; (repeat each T) {
  return (repeat each value)
}

func example&lt;each T&gt;(_ value: repeat each T) {
  let abstractTuple = tuplify(repeat each value)
  repeat print(each abstractTuple) // okay as of this proposal
}</code></pre><h2 id="proposals-in-progress">Proposals in Progress</h2><ul><li><p><strong>SE-0385: Custom Reflection Metadata</strong><br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0385-custom-reflection-metadata.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0385-custom-reflection-metadata/62777">Review</a>  |  🔄 <a href="https://forums.swift.org/t/returned-for-revision-se-0385-custom-reflection-metadata/63758">Returned</a></p></li><li><p><strong>SE-0387: Swift SDKs for Cross-Compilation</strong><br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0387-cross-compilation-destinations.md">Proposal</a>  |  💬 Reviews: <a href="https://forums.swift.org/t/se-0387-cross-compilation-destination-bundles/62875">1st</a>, <a href="https://forums.swift.org/t/second-review-se-0387-cross-compilation-swift-sdks-previously-destination-bundles/64660">2nd</a></p></li><li><p><strong>SE-0395: Observation</strong><br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0395-observability.md">Proposal</a>  |  💬 Reviews: <a href="https://forums.swift.org/t/se-0395-observability/64342">1st</a>, <a href="https://forums.swift.org/t/second-review-se-0395-observability/65261">2nd</a></p></li></ul><h2 id="recently-active-pitchesdiscussions">Recently Active Pitches/Discussions</h2><ul><li><p><a href="https://forums.swift.org/t/pitch-test-build-introspection/64884">Test Build Introspection</a></p></li><li><p><a href="https://forums.swift.org/t/convention-thin-function-pointers/65180"><code>@convention(thin)</code> function pointers</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-add-duration-nanoseconds/65181">add <code>Duration.nanoseconds(_:)</code></a></p></li><li><p><a href="https://forums.swift.org/t/pitch-introduce-objc-direct-attribute/65138">Introduce @objc_direct Attribute</a>​</p></li><li><p><a href="https://forums.swift.org/t/codable-synthesis-and-decoding-unavailable-values/64926">Codable synthesis and decoding unavailable values</a></p></li><li><p><a href="https://forums.swift.org/t/consistent-numeric-representation-in-strings-and-literals/64915">Consistent Numeric representation in Strings and Literals</a></p></li><li><p><a href="https://forums.swift.org/t/approaches-for-multiple-extension-block-doccomments/64685">Approaches for multiple extension block doccomments</a></p></li></ul><h2 id="other-developments-worth-mentioning">Other Developments Worth Mentioning</h2><p>If you want to enable Swift 6 features today, <a href="https://twitter.com/jamesdempsey/">James Dempsey</a> wrote <a href="https://www.swift.org/blog/using-upcoming-feature-flags/">a detailed article</a> on the Swift blog just a few days ago on how to do that. I had already enabled “Swift 6” mode in April in my apps and documented my experience <a href="https://www.fline.dev/preparing-for-swift-6/">here</a>.</p><p>Lastly, the Swift Core Team announced changes to how workgroups are named and operate in <a href="https://www.swift.org/blog/evolving-swift-project-workgroups/">this blog post</a>. Basically, there will be two tiers of groups: steering groups, responsible for overall strategic direction, and workgroups, focused on specific areas of the project. The core mission of diversity will be incorporated into all workgroups. Additionally, the Ecosystem Steering Group will be formed to support the Swift developer ecosystem, and a Contributor Experience Workgroup will create pathways for open-source contributions. Here’s an overview of all:</p><p><img src="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-may-23/swift-org.webp" alt="Swift Workgroups Diagram" loading="lazy" /></p><p><em>Source: swift.org</em></p><p>And that’s it for May. Have a great week of WWDC 😎 and until next time!</p><blockquote><p>💁🏻‍♂️ <strong>Enjoyed this article? Check out TranslateKit!</strong>
A drag &amp; drop translator for String Catalog files – it’s really easy.
<a href="https://apps.apple.com/app/apple-store/id6476773066?pt=549314&ct=fline.dev&mt=8"><strong>Get it now</strong></a> to machine-translate your app to up to 150 languages!</p></blockquote>]]></content:encoded>
<media:thumbnail url="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-may-23/hero.webp"/>
</item>
<item>
<title>Swift Evolution Monthly: March + April &apos;23</title>
<link>https://evolutionkit.dev/blog/swift-evolution-monthly-mar-apr-23/</link>
<guid isPermaLink="true">https://evolutionkit.dev/blog/swift-evolution-monthly-mar-apr-23/</guid>
<pubDate>Mon, 01 May 2023 00:00:00 +0000</pubDate>
<description><![CDATA[1-Year Anniversary: Summaries on GitHub! AsyncStream, Attached Macros (in SwiftPM), Package Publish, Parameter Packs, Feature Flags & Foundation Preview.]]></description>
<content:encoded><![CDATA[<p><img src="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-mar-apr-23/hero.webp" alt="Swift Evolution Monthly: March + April '23" /></p><p>It’s already been a whole year since I started writing this newsletter! 🥳 Can you believe it? I’ve had so much fun sharing all of the latest news and updates about Swift with you over the past year. Starting with a <a href="https://www.fline.dev/swift-evolution-monthly-first-issue/">recap of the Swift Evolution history</a> in the first issue of the newsletter, I managed to cover as many as 44 proposals already, and with this issue, I’m adding six more, reaching 50!</p><p>To celebrate this milestone, I’ve created <a href="https://github.com/FlineDev/swift-evolution">a GitHub project</a> with all my past summaries shared with this newsletter already. This should make it much easier for anyone in the community to find a specific proposal summary. I designed the repo in such a way that you can simply replace <code>apple</code> in a proposal’s GitHub URL (<code>https://github.com/apple/swift-evolution</code>) with <code>FlineDev</code> and you’ll directly get to the summary of the related proposal!</p><p>I also decided that starting with this newsletter, I will also always summarize one old proposal discussed and accepted <em>before</em> this newsletter was even kicked off that I find still relevant and interesting. This way, the repo should become even more useful as a “summary project” for all the sometimes too-detailed proposal documents. And I invite members of the community who already wrote proposal summaries in other places to contribute to the project, too! Or just write a summary for a topic you’ve always been interested in, writing a summary is a great way to learn more about Swift, I can tell from experience! 😉</p><p>Thank you so much for being a part of this journey with me so far. Here’s to another great year of Swift Evolution Monthly! 🍻🎉</p><h2 id="accepted-proposals">Accepted Proposals</h2><p>The first of the newly accepted proposals highly relates to an older proposal I didn’t cover yet. So, I think it’s most natural to start with this old proposal:</p><h3 id="se-0314-asyncstream-and-asyncthrowingstream">SE-0314: <code>AsyncStream</code> and <code>AsyncThrowingStream</code></h3><p><strong>Links:</strong> **📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0314-async-stream.md">Proposal</a> | 💬 Reviews: <a href="https://forums.swift.org/t/se-0314-asyncstream-and-asyncthrowingstream/48198">1st</a>, <a href="https://forums.swift.org/t/se-0314-second-review-asyncstream-and-asyncthrowingstream/49803">2nd</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0314-asyncstream-and-asyncthrowingstream/50699">Acceptance</a></p><p>We all have used many types conforming to the <code>Sequence</code> protocol, like <code>Array</code>, <code>Dictionary</code>, or <code>String</code>. It allows for easy iteration with  <code>for element in array</code>. The same treatment was added to the new Swift Concurrency world with <code>AsyncSequence</code>, which is pretty much the same as <code>Sequence</code> but the values aren’t immediately available, instead they come at a later time. But usage looks exactly the same, with only the <code>await</code> keyword added: <code>for await element in array</code>.</p><p>Actually, there’s one thing wrong with the sample code just provided: <code>array</code>. Because the <code>Array</code> type doesn’t conform to <code>AsyncSequence</code>, instead, we need new types that we can instantiate and return in our APIs, or that we can consume from system APIs. And that’s where <code>AsyncStream</code> and its throwing counterpart <code>AsyncThrowingStream</code> come into play. If you’re not familiar with streams, think of them as “async arrays”. This is a simplification of course, and creating an <code>AsyncStream</code> is quite different from an array. Here’s a simple example:</p><pre><code class="language-Swift">let swiftFileURL: URL = ...
let matches: (String) -&gt; Bool = { $0.contains(&quot;// TODO:&quot;) }

let matchingLineNumbersStream = AsyncStream&lt;Int&gt; { continuation in
   Task {
      var lineNumber: Int = 0
      for try await line in swiftFileUrl.lines {
         lineNumber += 1
         if matches(line) {
            continuation.yield(lineNumber)
         }
      }
      
      continuation.finish()
   }
}</code></pre><p>Note that we’re being passed a <code>continuation</code> which we pass new values to by calling <code>yield()</code> and when we reach the end of the “async array”, we call <code>.finish()</code>. This way we don’t have to write a custom iterator logic.</p><p>Then, consumers like some rule in a linting tool could use the stream like so:</p><pre><code class="language-Swift">for await lineNumber in matchingLineNumbersStream {
   violatingLines.append(lineNumber)
}</code></pre><p><em>Iterate an <code>Async(Throwing)Stream</code> like you do with any other <code>Sequence</code> type.</em></p><p>The cool thing about <code>AsyncStream</code> is that it’s not only useful for slow APIs, like calling data from a server. But it can also be used when receiving values very fast, faster actually than we can consume them on the call site. <code>AsyncStream</code> automatically buffers values in this case and sends them in the receiving order, so we never skip any values and things work as expected.</p><h3 id="se-0388-convenience-asyncstreammakestream-methods">SE-0388: Convenience AsyncStream.makeStream methods</h3><p><strong>Links:</strong> 📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0388-async-stream-factory.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0388-convenience-async-throwing-stream-makestream-methods/63139">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-with-modifications-se-0388-convenience-async-throwing-stream-makestream-methods/63568">Acceptance</a></p><p>Currently, when creating an <code>AsyncStream</code>, you get passed a <code>continuation</code> parameter into the trailing closure to send (or <code>.yield</code>) values to. In some cases, this works fine. But in many situations, you actually might want to pass around the <code>continuation</code> to some other places. And this proposal adds that capability:</p><pre><code class="language-Swift">let (stream, continuation) = AsyncStream.makeStream(of: Int.self)

await withTaskGroup(of: Void.self) { group in
   group.addTask {
      // code using `continuation`
   }
   
   group.addTask {
      // code using `stream`
   }
}</code></pre><p>Note the <code>makeStream(of:)</code> method returning a tuple containing the <code>continuation</code>. It’s also worth noting that this is making use of <code>@backDeployed(before:)</code> introduced recently in <a href="https://www.fline.dev/swift-evolution-monthly-october-22/#se-0376-function-back-deployment">SE-0376</a> to make this API available for projects targeting older OS versions than the ones Swift 5.9 will be included in. 💯</p><h3 id="se-0389-attached-macros">SE-0389: Attached Macros</h3><p><strong>Links:</strong> 📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0389-attached-macros.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0389-attached-macros/63165">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0389-attached-macros/63593">Acceptance</a>  |  🔮 <a href="https://github.com/apple/swift-evolution/blob/main/visions/macros.md">Vision</a></p><p>This is a continuation of <a href="https://www.fline.dev/swift-evolution-monthly-jan-feb-23/#se-0382-expression-macros">SE-0382</a> which introduced “Expression Macros”. While the latter focused on a more function-like structure that we could “call” from anywhere using <code>#</code>, this proposal focuses on “attaching” behavior to existing declarations like functions or types using <code>@</code>. This might remind you of <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0258-property-wrappers.md">SE-0258</a> which introduced <a href="https://docs.swift.org/swift-book/documentation/the-swift-programming-language/properties/#Property-Wrappers">property wrappers</a> that allowed attaching extra behavior to stored properties like done by SwiftUI with the likes of <code>@State</code>. And, in fact, this similarity is on purpose because, to some extent, “attached macros” are an extension of property wrappers to all kinds of declarations and are explicitly stated as “subsuming some of the[ir] behavior”.</p><p>For example, you could declare a “peer macro” named <code>AddCompletionHandler</code>:</p><pre><code class="language-Swift">@attached(peer, names: overloaded)
macro AddCompletionHandler(param: String = &quot;completionHandler&quot;)</code></pre><p>Then attach it to any <code>async</code> API like this (overriding the default param name):</p><pre><code class="language-Swift">@AddCompletionHandler(param: &quot;completion&quot;)
func fetchImage(url: URL) async throws -&gt; Image { ... }</code></pre><p>The macro would create an overloaded version of the same function with a non-<code>async</code> completion-handler as a parameter for you, for example:</p><pre><code class="language-Swift">func fetchImage(url: URL, completion: (Image) -&gt; Void) throws {
   Task {
      let image = try await self.fetchImage(url)
      completion(image)
   }
}</code></pre><p>The implementation of a macro is a bit involved and requires an understanding of <a href="https://github.com/apple/swift-syntax">swift-syntax</a> &amp; a new <code>SwiftSyntaxMacros</code> module. But the mere possibility to <em>adjust</em> our Swift code *using *Swift code is very powerful.</p><p>In total, there will be 5 different kinds of attached macros:</p><ol><li><p><strong>Peer Macros</strong>:<br />Attached to declarations to provide additional declarations.</p></li><li><p><strong>Member Macros</strong>:<br />Attached to types to add new members (like properties).</p></li><li><p><strong>Accessor Macros</strong>:<br />Attached to stored properties to turn them into computed properties with full access to the local context (unlike property wrappers).</p></li><li><p><strong>Member <em>Attribute</em> Macros</strong>:<br />Attached to types to apply attributes to all members (similar to <code>@objcMembers</code> or <code>@MainActor</code>).</p></li><li><p><strong>Conformance Macros</strong>:<br />Attached to types to add new protocol conformances.</p></li></ol><p>I really liked how Swift improved the developer experience by automatically synthesizing the conformance to types like <code>Codable</code> (<a href="https://github.com/apple/swift-evolution/blob/main/proposals/0166-swift-archival-serialization.md">SE-0166</a> + <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0295-codable-synthesis-for-enums-with-associated-values.md">SE-0295</a>), <code>Hashable</code>, or <code>Equatable</code> (both <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0185-synthesize-equatable-hashable.md">SE-0185</a>). And I’m really happy to see that we are now getting the power of implementing similarly magical APIs ourselves. 🪄</p><h3 id="se-0391-package-registry-publish">SE-0391: Package Registry Publish</h3><p><strong>Links:</strong> 📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0391-package-registry-publish.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0391-package-registry-publish/63405">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0391-swift-package-registry-authentication/64088">Acceptance</a></p><p>This proposal defines all things missing to allow for a unified way of publishing Swift packages to registries like the now <a href="https://www.swift.org/blog/swift-package-index-developer-spotlight/">officially</a> Apple-backed <a href="https://swiftpackageindex.com/">Package Index</a>:</p><ul><li><p>A metadata format for related URLs, authors &amp; organizations.</p></li><li><p>A package signature format for registries that require signing.</p></li><li><p>A new <code>package-registry publish</code> subcommand to “create a package source archive, sign it if needed, and publish it to a registry” all in one go.</p></li><li><p>A set of requirements for registries supporting signing to ensure security.</p></li></ul><p>The good news is that you probably won’t have to learn more about the details of this proposal thanks to the great work of <a href="https://github.com/daveverwer">Dave</a> &amp; <a href="https://github.com/finestructure">Sven</a>, plus the support of the Swift community, including <a href="https://swiftpackageindex.com/supporters">these 85 amazing people</a>. All that framework authors might need is the new <code>publish</code> subcommand, maybe not even that unless they use a CI for uploads, cause Apple might ship a UI for it in Xcode. 🤞</p><h3 id="se-0393-value-and-type-parameter-packs">SE-0393: Value and Type Parameter Packs</h3><p><strong>Links:</strong> 📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0393-parameter-packs.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0393-value-and-type-parameter-packs/63859">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-with-modifications-se-0393-value-and-type-parameter-packs/64382">Acceptance</a></p><p>This proposal adds two new keywords to the Swift language:</p><ul><li><p><code>each</code>: Precedes a type (like <code>some</code>) &amp; marks it as a “parameter pack”.</p></li><li><p><code>repeat</code>: Precedes a type/expression &amp; “expands” the related pack.</p></li></ul><p>But what is a “parameter pack” and what does it mean to “expand” one?</p><p>In Swift when writing functions that accept a variable number of values of (potentially) differing types, the best we can do if we don’t want to erase their types is to write a generic function like this:</p><pre><code class="language-Swift">func areEquivalent&lt;A, B, C&gt;(_ first: A, _ second: B, _ third: C) -&gt; Bool

// example usage
areEquivalent(&quot;42&quot;, 42, 42.0)  // =&gt; true</code></pre><p>While this function uses generics so we don’t have to write many overloads to the same function with different type specifications, it is restricted to taking exactly three parameters. But what if we wanted an <code>areEquivalent</code> implementation for any number of differing types? To support up to 10 parameters, we would need to define 10 different generic methods like the above, each with a growing number of generic types. But couldn’t we somehow tell Swift to do that for us?</p><p>Well, that’s exactly what this proposal does by means of <code>each</code> and <code>repeat</code>:</p><pre><code class="language-Swift">func areEquivalent&lt;each T&gt;(_ values: repeat each T) -&gt; Bool</code></pre><p>A “parameter pack” is what allows a function to accept an arbitrary number of arguments of any type, here: <code>each T</code>. The “expansion” of a pack is the process of unpacking its contents into individual arguments, here: <code>repeat each T</code>. The single function declaration above is “expanded” to function declarations with zero, one, two, three, and more parameters of (potentially) distinct types by Swift.</p><p>And that’s not all, there’s much more to this proposal – it’s actually quite detailed. The above is just a short intro to parameter packs, but it doesn’t even show the implementation side of it. Here’s an implementation from the proposal:</p><pre><code class="language-Swift">func zip&lt;each T, each U&gt;(firsts: repeat each T, seconds: repeat each U) -&gt; (repeat (each T, each U)) {
  return (repeat (each firsts, each seconds))
}</code></pre><p><em>Multiple parameter packs in one function are possible but are inferred to have the same size.</em></p><p>And this seems just the first step into the larger topic of variadic generics programming, a related pitch &amp; a related proposal are listed further below.</p><hr /><blockquote><p>✨ Want to see your ad here? Contact me at <a href="mailto:ads@fline.dev">ads@fline.dev</a> to get in touch.</p></blockquote><hr /><h3 id="se-0394-package-manager-support-for-custom-macros">SE-0394: Package Manager Support for Custom Macros</h3><p><strong>Links:</strong> 📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0394-swiftpm-expression-macros.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0394-package-manager-support-for-custom-macros/64170">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0394-package-manager-support-for-custom-macros/64589">Acceptance</a>  |  🔮 <a href="https://github.com/apple/swift-evolution/blob/main/visions/macros.md">Vision</a></p><p>With <a href="https://www.fline.dev/swift-evolution-monthly-jan-feb-23/#se-0382-expression-macros">SE-0382</a> “Expression Macros” &amp; SE-0389 “Attached Macros” (⬆️), we’re getting closer to a Swift world full of macros. But what if we wanted to share macros across projects or with the community in an open-source package?</p><p>This proposal adds a new target type to the Swift package manifest named <code>macro</code> which has the same shape as other target types like <code>target</code> or <code>testTarget</code>. But it behaves more like the <code>plugin</code> target type added in <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0303-swiftpm-extensible-build-tools.md">SE-0303</a>: When included in a project, the <code>macro</code> targets are built as executables so that the compiler can run them as part of the compilation process for any targets which depend on them. Also, like package plugins, the macro target will be executed in a sandbox that prevents file system and network access.</p><p>I’m looking forward to the macros the community will come up with, especially if Apple introduces how to use these new features to a wider audience at WWDC.</p><h2 id="proposals-in-progress">Proposals in Progress</h2><ul><li><p><strong>SE-0364: Warning for Retroactive Conformances of Ext. Types</strong><br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0364-retroactive-conformance-warning.md">Proposal</a>  |  💬 Reviews: <a href="https://forums.swift.org/t/se-0364-warning-for-retroactive-conformances-of-external-types/58922">1st</a>, <a href="https://forums.swift.org/t/second-review-se-0364-warning-for-retroactive-conformances-of-external-types/64615">2nd</a>  |  💁 <a href="https://www.fline.dev/swift-evolution-monthly-july-22/#se-0364-warning-for-retroactive-conformances-of-external-types">My Summary</a></p></li><li><p><strong>SE-0385: Custom Reflection Metadata</strong><br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0385-custom-reflection-metadata.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0385-custom-reflection-metadata/62777">Review</a>  |  🔄 <a href="https://forums.swift.org/t/returned-for-revision-se-0385-custom-reflection-metadata/63758">Returned</a></p></li><li><p><strong>SE-0386: New access modifier: <code>package</code></strong><br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0386-package-access-modifier.md">Proposal</a>  |  💬 Reviews: <a href="https://forums.swift.org/t/se-0386-package-access-modifier/62808">1st</a>, <a href="https://forums.swift.org/t/second-review-se-0386-package-access-modifier/64086">2nd</a></p></li><li><p><strong>SE-0387: Swift SDKs for Cross-Compilation</strong><br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0387-cross-compilation-destinations.md">Proposal</a>  |  💬 Reviews: <a href="https://forums.swift.org/t/se-0387-cross-compilation-destination-bundles/62875">1st</a>, <a href="https://forums.swift.org/t/second-review-se-0387-cross-compilation-swift-sdks-previously-destination-bundles/64660">2nd</a></p></li><li><p><strong>SE-0390: Noncopyable structs and enums</strong><br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0390-noncopyable-structs-and-enums.md">Proposal</a>  |  💬 Reviews: <a href="https://forums.swift.org/t/se-0390-noncopyable-structs-and-enums/63258">1st</a>, <a href="https://forums.swift.org/t/second-review-se-0390-noncopyable-structs-and-enums/63866">2nd</a></p></li><li><p><strong>SE-0392: Custom Actor Executors</strong><br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0392-custom-actor-executors.md">Proposal</a>  |  💬 Reviews: <a href="https://forums.swift.org/t/se-0392-custom-actor-executors/63599">1st</a>, <a href="https://forums.swift.org/t/second-review-se-0392-custom-actor-executors/64257">2nd</a></p></li><li><p><strong>SE-0395: Observation</strong><br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0395-observability.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0395-observability/64342">Review</a></p></li><li><p><strong>SE-0396: Conform <code>Never</code> to <code>Codable</code></strong><br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0396-never-codable.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0396-conform-never-to-codable/64469">Review</a></p></li><li><p><strong>SE-0397: Freestanding Declaration Macros</strong><br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0397-freestanding-declaration-macros.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0397-freestanding-declaration-macros/64655">Review</a>  |  🔮 <a href="https://github.com/apple/swift-evolution/blob/main/visions/macros.md">Vision</a></p></li><li><p><strong>SE-0398: Allow Generic Types to Abstract Over Packs</strong><br />📝 <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0398-variadic-types.md">Proposal</a>  |  💬 <a href="https://forums.swift.org/t/se-0398-allow-generic-types-to-abstract-over-packs/64661">Review</a></p></li></ul><h2 id="recently-active-pitchesdiscussions">Recently Active Pitches/Discussions</h2><ul><li><p>[Macro] <a href="https://forums.swift.org/t/macros-accessing-the-parent-context-of-a-syntax-node-passed-to-a-macro/64443">Accessing “parent context” of a syntax node passed to a macro</a></p></li><li><p>[Macro] <a href="https://forums.swift.org/t/pitch-optionset-macro/63547">@OptionSet macro</a></p></li><li><p>[Variadic] <a href="https://forums.swift.org/t/tuple-of-value-pack-expansion/64269">Tuple of value pack expansion</a></p></li><li><p>[Observe] <a href="https://forums.swift.org/t/some-suggestions-for-swift-observation/64410">Some suggestions for Swift Observation</a></p></li><li><p>[Observe] <a href="https://forums.swift.org/t/observing-changes-to-arbitrary-key-paths-on-move-only-structs/64436">Observing changes to arbitrary keypaths on move-only structs</a></p></li><li><p>[Other] <a href="https://forums.swift.org/t/pitch-is-case-expressions/64185">is case expressions</a></p></li><li><p>[Other] <a href="https://forums.swift.org/t/pitch-dependent-types-universes-stage-1-of-proof-driven-development/63754">Dependent Types &amp; Universes (Proof-Driven Development?)</a></p></li><li><p>[Other] <a href="https://forums.swift.org/t/pitch-import-c-structs-with-arc-pointer-members/64059">Import C structs with ARC pointer members</a></p></li><li><p>[Other] <a href="https://forums.swift.org/t/pitch-synthesize-init-of-structs/63688">Synthesize init of structs</a></p></li></ul><h2 id="other-developments-worth-mentioning">Other Developments Worth Mentioning</h2><p>I had already written about the Upcoming Feature flag with which you can try out Swift 6 features in <a href="https://www.fline.dev/swift-evolution-monthly-june-22/#se-0362-piecemeal-adoption-of-future-language-improvements">SE-0362</a>. Soon after I wrote <a href="https://www.fline.dev/preparing-for-swift-6/">this very popular article</a> about how you can use some Swift 6 features today, Swift.org <a href="https://github.com/apple/swift-org-website/pull/284">received</a> a very related improvement: Now you can filter proposals <a href="https://www.swift.org/swift-evolution/#?upcoming=true">with an upcoming feature flag</a> and you’ll even see the feature flag’s name right within the list:</p><p><img src="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-mar-apr-23/feature-flags-filter.webp" alt="" loading="lazy" /></p><p>In December 2022 Apple <a href="https://www.swift.org/blog/future-of-foundation/">announced</a> that they would be open-sourcing Foundation (or rather <em>rewriting</em> Foundation in the open). Less than 5 months later, they already <a href="https://www.swift.org/blog/foundation-preview-now-available/">announced</a> that a preview of this “future of Foundation” is <a href="https://github.com/apple/swift-foundation">available</a>, focusing on <code>FoundationEssentials</code> and <code>Internationalization</code>. <a href="https://github.com/apple/swift-foundation/blob/main/CONTRIBUTING.md">Contributions</a> are welcome! Time to test your apps with it and report bugs.</p><p>The second vision document (“A Vision for Macros”) has been <a href="https://forums.swift.org/t/accepted-vision-macros/63891">accepted</a> and is now <a href="https://github.com/apple/swift-evolution/blob/main/visions/macros.md">included</a> right within the Evolution GitHub repo in the <code>visions</code> folder.</p><p>And that’s all for March &amp; April. Until next time!</p><blockquote><p>💁🏻‍♂️ <strong>Enjoyed this article? Check out my app <strong>RemafoX</strong>!</strong>
A native Mac app that integrates with Xcode to help translate <strong>your</strong> app.
<a href="https://apps.apple.com/app/apple-store/id1605635026?pt=549314&ct=fline.dev&mt=8"><strong>Get it now</strong></a> to save time during development &amp; make localization easy.</p></blockquote>]]></content:encoded>
<media:thumbnail url="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-mar-apr-23/hero.webp"/>
</item>
<item>
<title>Swift Evolution Monthly Jan + Feb &apos;23</title>
<link>https://evolutionkit.dev/blog/swift-evolution-monthly-jan-feb-23/</link>
<guid isPermaLink="true">https://evolutionkit.dev/blog/swift-evolution-monthly-jan-feb-23/</guid>
<pubDate>Mon, 20 Mar 2023 00:00:00 +0000</pubDate>
<description><![CDATA[Expression Macros, Deprecate @UIApplicationMain, Forward Declared ObjC Interfaces, Swift 5.8 & 6 schedule]]></description>
<content:encoded><![CDATA[<p><img src="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-jan-feb-23/hero.webp" alt="Swift Evolution Monthly Jan + Feb '23" /></p><p>The last issue had an unusual delay already because I had to move the newsletter over from one service to another while I was on travel in Japan. This time around I had to <em>skip an entire month</em> because I had to move my <em>flat</em> from one city to another right after, which was a much much bigger task! 😱📦💪</p><p>In fact, I couldn’t work <em>at all</em> for about 5 weeks and the relocation is still not fully completed. But that’s how life is sometimes. At least I have a full workroom to myself now (instead of just a table in my bedroom), which could help to be more productive in the future. Also, I will finally have a <a href="https://twitter.com/Jeehut/status/1636770578790072341">real</a> <a href="https://iosdev.space/@Jeehut/110039629495967602">background</a> in <a href="https://www.twitch.tv/Jeehut">my Livetreams</a> instead of having to use a green screen like before (to hide my bed 😂).</p><p>Additionally, I’ve decided to change the structure of this newsletter a bit. I noticed that some proposals I summarized went through (sometimes significant) changes during the review process, such as <a href="https://www.fline.dev/swift-evolution-monthly-july-22/#se-0366-move-function-%E2%80%9Cuse-after-move%E2%80%9D-diagnostic">the <code>move</code> operator</a> which was first <a href="https://forums.swift.org/t/se-0366-second-review-take-operator-to-end-the-lifetime-of-a-variable-binding/61021">renamed to <code>take</code></a> and then <a href="https://forums.swift.org/t/combined-se-0366-third-review-and-se-0377-second-review-rename-take-taking-to-consume-consuming/61904">later to <code>consume</code></a>. It’s hard for me to keep up with these changes and edit my summaries (in time), plus edits aren’t even possible for sent emails.</p><p>So, starting with this issue, I will be summarizing only the <strong>accepted</strong> proposals. I’ll treat other proposals like I treated pitches/discussions before and list them in their own section with their title and related links so you can read up on what sounds interesting. The related links will also include the vision document from now on (if one exists), so you can read up on the bigger picture.</p><p>Also, I’ve created a new account for this newsletter on both Twitter &amp; Mastodon where I plan on posting <em>even shorter summaries</em> of proposals as soon as I’ve worked through them. I might also send out other Evolution-related posts from time to time, so if you’re interested in more frequent news, make sure to follow: <a href="https://twitter.com/SwiftEvolutionM">@SwiftEvolutionM</a> (Twitter) / <a href="https://iosdev.space/@SwiftEvolutionM">@SwiftEvolutionM@iosdev.space</a> (Mastodon)</p><p>With that said, let’s get to the summaries of all proposals accepted in Jan./Feb.:</p><h3 id="se-0382-expression-macros">SE-0382: Expression Macros</h3><p><strong>Links:</strong> <strong>📝</strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0382-expression-macros.md"><strong>Proposal</strong></a>* <em>| <strong>💬</strong> Reviews: <a href="https://forums.swift.org/t/se-0382-expression-macros/62090"><em>1st</em></a></em>, <em><a href="https://forums.swift.org/t/se-0382-second-review-expression-macros/63064"><em>2nd</em></a></em>  |  ✅ <em><a href="https://forums.swift.org/t/accepted-se-0382-expression-macros/63495"><em>Acceptance</em></a></em>  |  🔮 <a href="https://forums.swift.org/t/a-possible-vision-for-macros-in-swift/60900">Vision</a>*</p><p>This new feature will introduce a new kind of function-like structure called an “Expression Macro” which will come in very handy to write more expressive libraries and eliminate boilerplate in code. These new macros work very similarly to functions because they take data through arguments, do something with those data and return some new data. But the big difference is that their execution happens during compile time, which means that the data they operate on is not runtime user data, but it’s the source code of your app (or library)!</p><p>Yes, you heard that right, it’s like a little hook we get into the compilation process so we can eliminate having to repeat writing similar code in various places to make things in our code consistent. Because you have access to your source code in macros, they will even allow for new concepts currently impossible to write in Swift. Have you ever used <code>#filePath</code>,  <code>#function</code>, <code>#line</code>, <code>#selector</code>, <code>#colorLiteral</code>, <code>#imageLiteral</code> or other things starting with <code>#</code> in your code? Well, those are all built-in expressions that will be subsumed into macros and ship as macros in the Swift standard library. These should already give you an idea of what kind of features are possible with macros. Here are 9 more use cases for macros:</p><ol><li><p>Domain-specific languages (DSLs) – e.g. mathematics, database queries</p></li><li><p>Code generation – e.g. <code>JSON</code> to <code>Codable</code> struct</p></li><li><p>Debugging – e.g. print value of variable before &amp; after a function call</p></li><li><p>Performance optimization – replace runtime checks with compile-time checks</p></li><li><p>Syntax extensions – e.g. new control flow constructs or data types</p></li><li><p>Functional programming – e.g. simulate <a href="https://en.wikipedia.org/wiki/Currying">curried</a> functions</p></li><li><p>Code instrumentation – e.g. measure performance, monitor usage</p></li><li><p>Algorithmic complexity analysis – e.g. determine time complexity of sorting</p></li><li><p>Code obfuscation – e.g. for hard-coded <code>String</code>s like API keys</p></li></ol><p>It’s hard to tell if this proposal alone already enables all these use cases until we try this new feature out, for example, because the implementation will be sandboxed like with <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0303-swiftpm-extensible-build-tools.md#security">SwiftPM plugins</a>. But at least it’s a big first step toward the larger <a href="https://forums.swift.org/t/a-possible-vision-for-macros-in-swift/60900/5">vision</a>. While this sounds quite exciting, writing a macro has its own learning curve as you’ll have to make use of the <a href="https://github.com/apple/swift-syntax">swift-syntax</a> library and a new <code>SwiftSyntaxMacros</code> module that will provide what’s required to define macros.</p><p>I won’t go into all details of how to implement a macro, but it’s worth noting that there will be two parts to it: The declaration and the implementation. Much like with functions, where <code>func description(count: Int) -&gt; String</code> is the declaration and the code within <code>{ ... }</code> is the implementation. But with macros, those two are not necessarily within the same file and can/must be written separately:</p><pre><code class="language-Swift">import SwiftSyntax
import SwiftSyntaxBuilder
import _SwiftSyntaxMacros

// Implementation:
public struct StringifyMacro: ExpressionMacro {
  public static func expansion(
    of node: some FreestandingMacroExpansionSyntax,
    in context: some MacroExpansionContext
  ) -&gt; ExprSyntax {
    guard let argument = node.argumentList.first?.expression else {
      fatalError(&quot;compiler bug: the macro does not have any arguments&quot;)
    }

    return &quot;(\(argument), \(literal: argument.description))&quot;
  }
}

// Declaration:
@freestanding(expression)
macro stringify&lt;T&gt;(_: T) -&gt; (T, String) =
  #externalMacro(module: &quot;ExampleMacros&quot;, type: &quot;StringifyMacro&quot;)

// Usage:
let (a, b): (Double, String) = #stringify(1 + 2)</code></pre><p><em>Sample macro from the proposal. Another macro #externalMacro ties things together.</em></p><p><a href="https://twitter.com/dgregor79">Doug Gregor</a> from the Language Workgroup is maintaining <a href="https://github.com/DougGregor/swift-macro-examples">a GitHub repo</a> with many more sample implementations of macros if you’re interested.</p><p>I’m really looking forward to what new expression macros Apple will introduce during WWDC this year, and I’m also sure the community will come up with some creative uses to simplify app coding life, make code safer or streamline the API of their libraries.</p><h3 id="se-0383-deprecate-uiapplicationmain-and-nsapplicationmain">SE-0383: Deprecate @UIApplicationMain and @NSApplicationMain</h3><p><strong>Links:</strong> <strong>📝</strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0383-deprecate-uiapplicationmain-and-nsapplicationmain.md">Proposal</a>**| <strong>💬</strong> <a href="https://forums.swift.org/t/se-0383-deprecate-uiapplicationmain-and-nsapplicationmain/62375">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0383-deprecate-uiapplicationmain-and-nsapplicationmain/62645">Acceptance</a></p><p>The ‘Introduction’ section of this proposal summarizes this pretty well:</p><blockquote><p><code>@UIApplicationMain</code> and <code>@NSApplicationMain</code> used to be the standard way for iOS and macOS apps respectively to declare a synthesized platform-specific entrypoint for an app. These functions have since been obsoleted by <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0281-main-attribute.md">SE-0281</a>’s introduction of the <code>@main</code> attribute, and they now represent a confusing bit of duplication in the language. This proposal seeks to deprecate these alternative entrypoint attributes in favor of <code>@main</code> in pre-Swift 6, and it makes their use in Swift 6 a hard error.</p></blockquote><p>There’s not much more to say about it. But you could use this as a reminder to switch from <code>@UIApplicationMain</code> to <code>@main</code> today to prevent the warning and be Swift-6 conformant. Or wait for the fix-it to appear in a future Xcode release.</p><h3 id="se-0384-importing-forward-declared-objective-c-interfaces-and-protocols">SE-0384: Importing Forward Declared Objective-C Interfaces and Protocols</h3><p><strong>Links:</strong> <strong>📝</strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0384-importing-forward-declared-objc-interfaces-and-protocols.md">Proposal</a>**| <strong>💬</strong> <a href="https://forums.swift.org/t/se-0384-importing-forward-declared-objective-c-interfaces-and-protocols/62392">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0384-importing-forward-declared-objective-c-interfaces-and-protocols/62670">Acceptance</a></p><p>This concerns everyone calling code written in Objective-C from within Swift (like when using older libraries). The idea is to port a common workaround for cyclic dependencies in Objective-C code to Swift in an automatically synthesized way:</p><p>In Objective-C, the public API of a type is declared in a header <code>.h</code> file. When a type named <code>User</code> wants to declare a public property <code>credentials</code> which has its own type <code>Credentials</code>, it needs to import its header file  <code>Credentials.h</code>. Now, when the <code>Credentials</code> type had a property named <code>user</code> of type <code>User</code>, it would need to import the header file <code>User.h</code> which is a cycling dependency that is not allowed and causes a compiler error. To fix this, there’s a workaround in Objective-C where one declares an empty type to specify that a specific type “exists” without actually importing its header, this technique is called “<a href="https://en.wikipedia.org/wiki/Forward_declaration">forward-declaration</a>”.</p><p>To use such Objective-C APIs in Swift, one had to “forward-declare” those types in Swift explicitly, which is very inconvenient. In the future, that won’t be necessary. Swift will automatically synthesize forward-declared types in Swift as follows:</p><pre><code class="language-Swift">// @class Foo turns into
@available(*, unavailable, message: “This Objective-C class has only been forward declared; import its owning module to use it”)
class Foo : NSObject {}

// @protocol Bar turns into
@available(*, unavailable, message: “This Objective-C protocol has only been forward declared; import its owning module to use it”)
protocol Bar : NSObjectProtocol {}</code></pre><p>This new behavior will be turned on by default in Swift 6, but needs to be opted-in with Swift 5.x by using the flag <code>-enable-import-objc-forward-declarations</code>.</p><blockquote><p>📧 <em>To receive future issues via <strong>email</strong>, subscribe to the newsletter <a href="https://swiftevolution.substack.com/?ref=flinedev">here</a>.</em></p></blockquote><h2 id="proposals-in-progress">Proposals in Progress</h2><ul><li><p><strong>SE-0385: Custom Reflection Metadata</strong><br /><strong>📝</strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0385-custom-reflection-metadata.md">Proposal</a>**| <strong>💬</strong> <a href="https://forums.swift.org/t/se-0385-custom-reflection-metadata/62777">Review</a>  |  🔄 <a href="https://forums.swift.org/t/returned-for-revision-se-0385-custom-reflection-metadata/63758"><em>Returned</em></a></p></li><li><p><strong>SE-0386: New access modifier: <code>package</code></strong><br /><strong>📝</strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0386-package-access-modifier.md">Proposal</a>**| <strong>💬</strong> <a href="https://forums.swift.org/t/se-0386-package-access-modifier/62808">Review</a></p></li><li><p><strong>SE-0387: Cross-Compilation Destination Bundles</strong><br /><strong>📝</strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0387-cross-compilation-destinations.md">Proposal</a>**| <strong>💬</strong> <a href="https://forums.swift.org/t/se-0387-cross-compilation-destination-bundles/62875">Review</a></p></li><li><p><strong>SE-0388: Convenience AsyncStream.makeStream methods</strong><br /><strong>📝</strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0388-async-stream-factory.md">Proposal</a>**| <strong>💬</strong> <a href="https://forums.swift.org/t/se-0388-convenience-async-throwing-stream-makestream-methods/63139">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-with-modifications-se-0388-convenience-async-throwing-stream-makestream-methods/63568">Acceptance</a> (summary in next issue)</p></li><li><p><strong>SE-0389: Attached Macros</strong><br /><strong>📝</strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0389-attached-macros.md">Proposal</a>**| <strong>💬</strong> <a href="https://forums.swift.org/t/se-0389-attached-macros/63165">Review</a>  |  ✅ <a href="https://forums.swift.org/t/accepted-se-0389-attached-macros/63593">Acceptance</a> (summary in next issue)</p></li><li><p><strong>SE-0390: Noncopyable structs and enums</strong><br /><strong>📝</strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0390-noncopyable-structs-and-enums.md">Proposal</a>**| <strong>💬</strong> <a href="https://forums.swift.org/t/se-0390-noncopyable-structs-and-enums/63258">Review</a></p></li><li><p><strong>SE-0391: Package Registry Publish</strong><br /><strong>📝</strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0391-package-registry-publish.md">Proposal</a>**| <strong>💬</strong> <a href="https://forums.swift.org/t/se-0391-package-registry-publish/63405">Review</a></p></li><li><p><strong>SE-0392: Custom Actor Executors</strong><br /><strong>📝</strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0392-custom-actor-executors.md">Proposal</a>**| <strong>💬</strong> <a href="https://forums.swift.org/t/se-0392-custom-actor-executors/63599">Review</a></p></li></ul><h2 id="recently-active-pitchesdiscussions"><strong>Recently Active Pitches/Discussions</strong></h2><p>Some threads inside the “Evolution” category with activity within the last 2 months I didn’t link yet. I’ll cover them in detail once (and if) they become proposals:</p><ul><li><p><a href="https://forums.swift.org/t/pitch-freestanding-macros/62811">Freestanding macros</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-rename-public-snake-case-attributes-to-camelcase/62574">Rename public snake_case attributes to camelCase</a></p></li><li><p><a href="https://forums.swift.org/t/un-pyramid-of-doom-the-with-style-methods/62360">Un-pyramid-of-doom the <code>with</code> style methods</a></p></li><li><p><a href="https://forums.swift.org/t/pre-pitch-package-argument-syntax/63031"><code>@package</code> argument syntax</a></p></li><li><p><a href="https://forums.swift.org/t/compound-variable-names/37963">Compound variable names</a></p></li><li><p><a href="https://forums.swift.org/t/performance-annotations/54441">Performance annotations</a></p></li><li><p><a href="https://forums.swift.org/t/prepitch-cancel-operator/63384"><code>cancel</code> operator</a></p></li><li><p><a href="https://forums.swift.org/t/extensible-enumerations-for-non-resilient-libraries/35900">Extensible Enumerations for Non-Resilient Libraries</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-stop-inferring-actor-isolation-based-on-property-wrapper-usage/63262">Stop inferring actor isolation based on property wrapper usage</a></p></li><li><p><a href="https://forums.swift.org/t/proposal-draft-for-is-case-pattern-match-boolean-expressions/58260">Proposal draft for <code>is case</code> (pattern-match boolean expressions)</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-constrain-implicit-raw-pointer-conversion-to-bitwise-copyable-values/63314">Constrain implicit raw pointer conversion to bitwise-copyable values</a></p></li></ul><hr /><blockquote><p>✨ Want to see your ad here? Contact me at <a href="mailto:ads@fline.dev">ads@fline.dev</a> to get in touch.</p></blockquote><hr /><h2 id="other-developments-worth-mentioning"><strong>Other Developments worth Mentioning</strong></h2><p>I’ve already presented several features that will find their way into one of the next Swift versions (e.g. <code>5.8</code>) but that are opt-in for Swift 5.x and will only be turned on by default in Swift 6, like the last proposal summarized above. In <a href="https://forums.swift.org/t/design-priorities-for-the-swift-6-language-mode/62408">this thread</a>, the Language Workgroup has now clarified the 3 focus areas for all breaking changes planned for Swift 6: Data-race <strong>safety</strong> by default, <strong>performance</strong> predictability, and package <strong>ecosystem</strong> scalability. Read the full post for more details.</p><p>Further down in the thread, <a href="https://forums.swift.org/t/design-priorities-for-the-swift-6-language-mode/62408/3">asked</a> for a rough idea of when we can expect Swift 6, Doug Gregor from the Language Workgroup <a href="https://forums.swift.org/t/design-priorities-for-the-swift-6-language-mode/62408/15">clarifies</a> that <strong>Swift 6 definitely won’t be released within 2023</strong>. So there’s still some time until we can expect these opt-in features to be turned on by default.</p><p>That’s why I’d like to remind everyone to consider opting into these potentially source-breaking opt-in features as soon as <a href="https://forums.swift.org/t/swift-5-8-release-process/61540">Swift 5.8 is released</a>, which should happen within the next 30 days if <a href="https://en.wikipedia.org/wiki/Swift_(programming_language)#Version_history">history</a> repeats. Like Doug says in the post, by doing so: “Developers will reap the benefits from these improvements sooner, rather than wait until the Swift 6 language version is available and complete.” Which will take a while. See <a href="https://www.fline.dev/swift-evolution-monthly-june-22/#se-0362-piecemeal-adoption-of-future-language-improvements">my summary of SE-0362</a> for how to opt in.</p><p>And that’s it for this issue. Til next time!</p><blockquote><p>💁🏻‍♂️ <strong>Enjoyed this article? Check out my app <strong>RemafoX</strong>!</strong>
A native Mac app that integrates with Xcode to help translate <strong>your</strong> app.
<a href="https://apps.apple.com/app/apple-store/id1605635026?pt=549314&ct=fline.dev&mt=8&ref=fline.dev"><strong>Get it now</strong></a> to save time during development &amp; make localization easy.</p></blockquote>]]></content:encoded>
<media:thumbnail url="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-jan-feb-23/hero.webp"/>
</item>
<item>
<title>Swift Evolution Monthly: December &apos;22</title>
<link>https://evolutionkit.dev/blog/swift-evolution-monthly-december-22/</link>
<guid isPermaLink="true">https://evolutionkit.dev/blog/swift-evolution-monthly-december-22/</guid>
<pubDate>Fri, 13 Jan 2023 00:00:00 +0000</pubDate>
<description><![CDATA[Registry auth, Opt-In Reflection, if-switch Expressions, Vision documents, DiscardingTaskGroups, and Foundation rewrite.]]></description>
<content:encoded><![CDATA[<p><img src="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-december-22/hero.webp" alt="Swift Evolution Monthly: December '22" /></p><p>One of the <strong>side effects of Elon Musk taking over Twitter</strong> was that the provider hosting this very newsletter is <a href="http://help.getrevue.co/en/articles/6819675-we-ve-made-the-difficult-decision-to-shut-down-revue">being shut down</a> as soon as this month. So, while I’m still traveling Japan (sadly, only a few days left 😔), I had to find a new provider and <strong>migrate</strong> everything over, which is why this issue comes unusually late. And that’s also why the design and sender of the newsletter will look different if you’re reading this as an email newsletter.</p><p>Here’s the <strong>new link</strong> for the newsletter: <a href="https://swiftevolution.substack.com/">https://swiftevolution.substack.com</a><br />If you prefer an **RSS **reader, use this: <a href="https://swiftevolution.substack.com/feed">https://swiftevolution.substack.com/feed</a></p><p>I skipped the November issue on purpose, as there weren’t enough interesting new proposals to cover from the perspective of app developers. But December had some interesting ones incoming, and there were even <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0383-deprecate-uiapplicationmain-and-nsapplicationmain.md">two</a> <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0384-importing-forward-declared-objc-interfaces-and-protocols.md">proposals</a> posted in January, which I will summarize in the next issue. I also decided to move <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0382-expression-macros.md">one more proposal</a> summary to the next issue, otherwise, this text would have been too long.</p><p>Without further ado, let’s get on with what happened in Nov/Dec!</p><h2 id="accepted-proposals"><strong>Accepted Proposals</strong></h2><p>The following proposal already presented in the past has been <strong>accepted</strong>:</p><ul><li><p><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0374-clock-sleep-for.md"><strong>SE-0374: Add sleep(for:) to Clock</strong></a><br /><a href="https://forums.swift.org/t/accepted-se-0374-add-sleep-for-to-clock/62148">Acceptance</a> <strong>✅</strong> | <a href="https://www.fline.dev/swift-evolution-monthly-october-22/#se-0374-add-sleepfor-to-clock">My Summary</a> 📋</p></li></ul><h2 id="proposals-in-reviewrevisionwaiting"><strong>Proposals In Review/Revision/Waiting</strong></h2><blockquote><p><strong>You can still provide feedback</strong> for these proposals**. The current <a href="https://apple.github.io/swift-evolution/#?status=rejected">rejection</a> rate is **&lt;<strong>10%, so <strong>they’re</strong>likely <strong>to</strong>get accepted. <a href="https://github.com/apple/swift-evolution/blob/main/process.md#proposal-states">Revisions</a> are more common.</strong></p></blockquote><h3 id="se-0378-package-registry-authentication">SE-0378: Package Registry Authentication</h3><p><strong>Links:</strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0378-package-registry-auth.md"><strong>Proposal Document</strong></a>**📝 | **<a href="https://forums.swift.org/t/se-0378-swift-package-registry-authentication/61436"><strong>Review</strong></a><strong>🧵</strong></p><p>Before we get to the news of this proposal, let me first clarify what a “package registry” is, as this newsletter was started <em>after</em> they were accepted to Swift and thus I didn’t cover them yet. <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0292-package-registry-service.md">SE-0292: Package Registry Service</a>, which was only recently shipped with Swift 5.7 (in Xcode 14), adds an alternative way of declaring package dependencies when using SwiftPM. Instead of using Git and its actions like <code>clone</code> or <code>checkout</code> for fetching dependencies by SwiftPM, the idea of a package registry is to define a <strong>RESTful API</strong> as an alternative to fetching via Git. A true API like provided by a package registry has performance and reliability advantages compared to using Git for dependency resolution and fetching. The good news is, from an app or framework developers perspective, these details are hidden by SwiftPM and the registry services that implement them. Unless you plan on implementing such a registry service yourself (which might make sense for larger companies, please read the full proposals in that case!), all you need to know is this:</p><p>Thanks to SE-0292, starting with Swift 5.7 whenever you add a dependency to your projects using SwiftPM, you can decide to either provide the GitHub URL (which was always possible) or alternatively provide a sort of identifier for the project consisting of a <code>scope</code> and the <code>name</code> of the package, e.g. something like <code>FlineDev/HandySwift</code>. In this example, <code>FlineDev</code> is my personal GitHub organization name which serves as the scope and <code>HandySwift</code> (a lib where I extract my reusable Swift code to) uniquely identifies a convenience library <em>within</em> that scope. Now, SwiftPM will search package registries you’re signed in to in order to find and download a version of my <code>HandySwift</code> library.</p><p>Yes, you read that right: You need to first be signed in to a package registry. Also, of course the library needs to be available through that registry. Apple <a href="https://www.swift.org/blog/focus-areas-2023/#package-registry">announced</a> that they are actually aiming to (effectively) replace the currently Git-based dependency management with a registry-based one long term. They will cooperate with the already useful <a href="https://swiftpackageindex.com/">Swift Package Index</a> project (a website that helps discover packages, hosts documentation &amp; more), which Dave Werver, one of the projects main contributors, confirmed <a href="https://iosdevweekly.com/issues/586#start">in his newsletter</a>. This is likely to become a one-stop place for all of Swift developers to get Open Source libraries from which (I can imagine) could even become the default server built into SwiftPM at some point if adoption is high, similar to how things work with <a href="https://cocoapods.org/">CocoaPods</a> already (or <a href="https://rubygems.org/">RubyGems</a> for Ruby / <a href="https://pypi.org/">PyPI</a> for Python / <a href="https://www.npmjs.com/">npm</a> for JavaScript). But we’ll see how things will turn out.</p><p>Now, the new thing this proposal introduces is another authentication method: Currently, only <a href="https://en.wikipedia.org/wiki/Basic_access_authentication">basic authentication</a> is supported, which limits some interactions. This proposal aims to add <a href="https://stackoverflow.com/a/27119226/3451975">token authentication</a> and fixes some security aspects of the current authentication system (no project-level auth file &amp; use Keychain on macOS). I’m happy to hear that we are finally getting closer to having a faster and more reliable Swift dependency management system.</p><h3 id="se-0379-swift-opt-in-reflection-metadata">SE-0379: Swift Opt-In Reflection Metadata</h3><p><strong>Links:</strong> <strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0379-opt-in-reflection-metadata.md">Proposal Document</a> 📝 | <a href="https://forums.swift.org/t/se-0379-opt-in-reflection-metadata/61714">Review</a> 🧵</strong></p><p>Are you making use of reflection APIs in Swift in your apps today? As a reminder: Reflection is the act of building your logic upon the structure of your (or someone else’s) Swift code. For example, for a type <code>Person</code> you could use the <code>Mirror</code> type and pass it an object of type <code>Person</code> to get information about the properties and their names to act accordingly. You might think that this seems useful in some rare scenarios, but I’m sure you’ve used reflection APIs already. If you’ve done any kind of debugging, chances are that you might have used one of the <code>print</code>, <code>debugPrint</code> or <code>dump</code> methods and passed them an object already. Guess what, the reason these give you some useful information is that they are making use of Reflection under the hoods!</p><p>But independent of if you’re planning on making use of reflection APIs explicitly sometime in the future or not, this proposal will profit anyone: Because it introduces fine-grained control over when reflection on a type is needed and when it is not and provides compile-time feedback. Basically, up until now, all code had to be compiled in a way that made reflection possible by adding metadata to your app binary, such as the property names <code>firstName</code> and <code>lastName</code> for a type like <code>Person</code> – just in case some library or SDK you were using relied on reflection like SwiftUI does for tracking changes in your model. Of course, this means that it is much easier to reverse-engineer our compiled code back to its original code form with these kinds of metadata than it would be if the name of the property wouldn’t be clear. Also, it is currently possible to completely turn off reflection metadata generation without any compiler warnings, which can lead to unexpected behavior.</p><p>This proposal aims to solve that by introducing a new <code>Reflectable</code> protocol to mark types that should support reflection metadata explicitly, so only for those types full metadata is provided. A migration path is provided so existing code doesn’t break immediately. Instead, Swift users will (probably) get a warning at first, so they can migrate their types over to <code>Reflectable</code>. Only once Swift 6 is out, the new behavior will be turned on by default (use the flag <code>-enable-full-reflection-metadata</code> to turn it on before that). For those who want to use reflection explicitly in their own code, they’ll be able to specify that their functions only work on types that conform to <code>Reflectable</code> and this way can be sure they can reflect on the provided data. And for those who just want to use APIs that use reflection under the hood, they will get an error at compile-time if they pass in data that doesn’t conform to <code>Reflectable</code>, making Swift reflection code safer, more reliable, and harder to reverse-engineer all at the same time.</p><h3 id="se-0380-if-and-switch-expressions">SE-0380: <code>if</code> and <code>switch</code> expressions</h3><p><strong>Links:</strong> <strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0380-if-switch-expressions.md">Proposal Document</a> 📝 | <a href="https://forums.swift.org/t/se-0380-if-and-switch-expressions/61899">Review</a> 🧵</strong></p><p>Consider this sample code showing a portion of logic for a Chess game app, read especially the comments I’ve added showing different implementation patterns:</p><pre><code class="language-Swift">class ChessGame {
   enum Direction: CaseIterable {
      case up, right, down, left, upRight, downRight, downLeft, upLeft
   }

   enum Piece {
      case pawn, rook, knight, bishop, queen, king

      // implemented as if-else with multiple returns
      var maxFieldsCanMoveInOneTurn: Int {
         if self == .pawn || self == .king {
            return 1
         } else if self == .knight {
            return 3
         } else {
            return 7
         }
      }
   }

   func movementLogic(of piece: Piece) {
      // implemented as switch-case with multiple returns in a self-executing closure
      let movableDirectionsForWhitePlayer: [Direction] = {
         switch piece {
         case .pawn: return [.up]
         case .rook: return [.up, .right, .down, .left]
         case .bishop: return [.upRight, .downRight, .downLeft, .upLeft]
         case .knight, .queen, .king: return Direction.allCases
         }
      }()

      // implemented as switch-case with Swift's definite initialization feature
      let movableDirectionsForBlackPlayer: [Direction]
      switch piece {
      case .pawn:
         movableDirectionsForBlackPlayer = [.down]
      case .rook:
         movableDirectionsForBlackPlayer = [.up, .right, .down, .left]
      case .bishop:
         movableDirectionsForBlackPlayer = [.upRight, .downRight, .downLeft, .upLeft]
      case .knight, .queen, .king:
         movableDirectionsForBlackPlayer = Direction.allCases
      }

      // …
   }
}</code></pre><p>Of course, this code could be refactored in multiple ways, but let’s stick to this code example for educational purposes. There are cases when some developers (including me) actually want this kind of in-line structure, especially if we want to return different but simple and clear values for different cases in code. Well, I have great news for you, because this proposal is doing exactly that and is simplifying the above code in many ways:</p><p>First, we no longer need to state the <code>return</code> keyword in <code>if</code> or <code>switch</code> statements if (and only if) all branches have exactly one statement and when the type of this statement is the same for all of them (independently!). Second, we no longer have to write a self-executing closure in these cases anymore, we can directly assign to variables from a <code>if</code> or <code>switch</code> statement. The latter aspect actually is what differentiates a mere <code>statement</code> from an <code>expression</code>: An expression always evaluates to a value, where an <code>if</code> or <code>switch</code> <em>statement</em> is only a structure for conditional code, a statement doesn’t (necessarily) evaluate to a value. But <code>if</code> and <code>switch</code> now will be usable as <em>expressions</em> when returning from functions/properties/closures or when assigning to variables.</p><p>With this proposal, the above code can be written as:</p><pre><code class="language-Swift">class ChessGame {
   enum Direction: CaseIterable {
      case up, right, down, left, upRight, downRight, downLeft, upLeft
   }

   enum Piece {
      case pawn, rook, knight, bishop, queen, king

      // no need for any return keyword
      var maxFieldsCanMoveInOneTurn: Int {
         if self == .pawn || self == .king { 1 }
         else if self == .knight { 3 } else { 7 }
      }
   }


   func movementLogic(of piece: Piece) {
      // no return keyword, no need for self-executing closure
      let movableDirectionsForWhitePlayer: [Direction] =
         switch piece {
         case .pawn: [.up]
         case .rook: [.up, .right, .down, .left]
         case .bishop: [.upRight, .downRight, .downLeft, .upLeft]
         case .knight, .queen, .king: Direction.allCases
         }

      // no return keyword, no need for definite initialization
      let movableDirectionsForBlackPlayer: [Direction] =
         switch piece {
         case .pawn: [.down]
         case .rook: [.up, .right, .down, .left]
         case .bishop: [.upRight, .downRight, .downLeft, .upLeft]
         case .knight, .queen, .king: Direction.allCases
         }

      // …
   }
}</code></pre><p>I highlighted the differences in the comments. Isn’t this much cleaner? I personally use self-executing closures from time to time, so now being able to get rid of them alongside the return keyword is really making the code read more naturally to me. Today I prefer to put each return in a <code>switch-case</code> in its own line plus an empty line before the next case for best readability, causing them to become really bloated (see <a href="https://github.com/FlineDevPublic/OpenFocusTimer/blob/a33ea48b8eab6db05d9dee508982e29f839fc37a/Sources/Settings/SettingsState.swift#L17-L42">here</a> for example). I’ll for sure consider returning in one line like this in the future!</p><h3 id="se-0381-discardingtaskgroups">SE-0381: DiscardingTaskGroups</h3><p><strong>Links:</strong> <strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0381-task-group-discard-results.md">Proposal Document</a> 📝 | <a href="https://forums.swift.org/t/se-0381-discardresults-for-taskgroups/62072">Review</a> 🧵</strong></p><p>This one is an improvement to Structured Concurrency in Swift, primarily aimed at improving memory management on the server. If you are new to Swifts’ new concurrency mechanisms such as <code>async</code>/<code>await</code> or <code>with(Throwing)TaskGroup</code>, you might want to read up on the two most relevant proposals’ “Proposed Solution” sections as I can’t summarize them in short here and they are pretty well written: <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0296-async-await.md#proposed-solution-asyncawait">SE-0296 Async/await</a> and <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0304-structured-concurrency.md#proposed-solution">SE-0304 Structured concurrency</a>.</p><p>In short, this proposal introduces two new <code>TaskGroup</code> variants (we currently have <code>TaskGroup</code> and <code>ThrowingTaskGroup</code>) which do not work like a sequence and thus they don’t conform to <code>AsyncSequence</code> (unlike <code>TaskGroup</code>/<code>ThrowingTaskGroup</code>). Instead, they automatically clean up any child <code>Task</code>s that complete, and they could  be potentially made to conform to <code>Sendable</code>, which is planned for a future proposal. The new types <code>DiscardingTaskGroup</code> and <code>ThrowingDiscardingTaskGroup</code> are provided as a parameter to the new <code>with(Throwing)DiscardingTaskGroup</code> global function. Other than the already mentioned differences, they work exactly like the previous task group types (and their related global function <code>with(Throwing)TaskGroup</code>).</p><p>The automatic child task clean-up nature makes these new types suitable for any situation where events are consumed for a longer period of time while creating (potentially long-running) tasks. The perfect use case for this is an HTTP or RPC server that handles an indefinite amount of requests. It’s not possible to write memory-efficient concurrency code for these kinds of scenarios right now.</p><p>It’s impressive to see how Swift on the Server is moving forward steadily over such a long period of time already, and there are still so many more things planned!</p><blockquote><p>📧 <strong>To receive future issues via <strong>email</strong>, subscribe to the newsletter <a href="https://swiftevolution.substack.com/">here</a>.</strong></p></blockquote><h2 id="recently-active-pitchesdiscussions"><strong>Recently Active Pitches/Discussions</strong></h2><p>Some threads inside the “Evolution” category with activity within the last 2 months I didn’t link yet. I’ll cover them in detail once (and if) they become proposals:</p><ul><li><p><a href="https://forums.swift.org/t/pitch-observation/62051">Observation</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-reflection/61438">Reflection</a></p></li><li><p><a href="https://forums.swift.org/t/single-quoted-character-literals-why-yes-again/61898">Single Quoted Character Literals</a></p></li><li><p><a href="https://forums.swift.org/t/new-access-modifier-package/61459">New Access Modifier: package</a></p></li><li><p><a href="https://forums.swift.org/t/inout-variables-in-for-in-loops/61380">Inout variables in for-in loops</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-custom-metadata-attributes/62016">Custom Metadata Attributes</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-contains-for-ranges/61818"><code>contains(_:)</code> for Ranges</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-cross-compilation-destination-bundles/61777">Cross-Compilation Destination Bundles</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-result-builder-scoped-unqualified-lookup/62190">Result builder scoped unqualified lookup</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-allow-property-wrappers-on-let-declarations/61750">Allow Property Wrappers on Let Declarations</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-dont-copy-self-when-calling-non-mutating-methods/61707">Don’t copy <code>self</code> when calling non-mutating methods</a></p></li></ul><hr /><blockquote><p>✨ Want to see your ad here? Contact me at <a href="mailto:ads@fline.dev">ads@fline.dev</a> to get in touch.</p></blockquote><hr /><h2 id="other-developments-worth-mentioning"><strong>Other Developments worth Mentioning</strong></h2><p>I noticed that a new process seems to have emerged in Swift Evolution which I would call “Vision-Driven Development”. We’ve always had <a href="https://github.com/apple/swift/tree/main/docs#manifestos">manifestos</a> in the Swift open-source project, like the <a href="https://github.com/apple/swift/blob/main/docs/StringManifesto.md">StringManifesto</a> or the recently very relevant <a href="https://github.com/apple/swift/blob/main/docs/GenericsManifesto.md">GenericsManifesto</a> and <a href="https://github.com/apple/swift/blob/main/docs/OwnershipManifesto.md">OwnershipManifesto</a>. Each of these claimed to be a vision for their topic. I’ve also seen sometimes that the first proposal of a related set of proposals was partly used as some kind of vision document, like <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0350-regex-type-overview.md">SE-0350 Regex Type and Overview</a>.</p><p>But as the Swift code base grows, the Swift Evolution process evolves and so we got a <a href="https://forums.swift.org/t/the-role-of-vision-documents-in-swift-evolution/62101">formalization of these kinds of vision documents</a>. Basically, the <a href="https://github.com/apple/swift-evolution/tree/main/proposals"><code>proposals</code> directory</a> in the <a href="https://github.com/apple/swift-evolution">Swift Evolution GitHub repo</a> has been joined by a <a href="https://github.com/apple/swift-evolution/tree/main/visions"><code>visions</code> directory</a>. And all vision documents will go through a lightweight (internal) review process before getting officially “accepted” and therefore will be even more reliable than before, where the process of the creation of these documents wasn’t clear.</p><p>The first vision already <a href="https://forums.swift.org/t/accepted-a-vision-for-using-swift-from-c/62102/1">accepted</a> is “<a href="https://github.com/apple/swift-evolution/blob/main/visions/using-swift-from-c%2B%2B.md">Using Swift from C++</a>” (see <a href="https://forums.swift.org/t/a-forward-vision-for-c-and-swift-interoperability/62150">discussion</a>). Two more <em>prospective</em> vision documents have been posted, one about <a href="https://github.com/hborla/swift-evolution/blob/variadic-generics-vision/vision-documents/variadic-generics.md">Variadic Generics</a> (discuss <a href="https://forums.swift.org/t/a-vision-for-variadic-generics-in-swift/61316">here</a>) and one about <a href="https://gist.github.com/DougGregor/4f3ba5f4eadac474ae62eae836328b71">Macros</a> (discuss <a href="https://forums.swift.org/t/a-possible-vision-for-macros-in-swift/60900">there</a>). This kind of formalization is great to see, as it further streamlines the Evolution process.</p><p>Apart from that, there has been some exciting news from Apple regarding Swift: Firstly, the Swift projects focus areas for 2023 were <a href="https://www.swift.org/blog/focus-areas-2023/">announced</a> on the Swift blog which is well worth a read (<a href="https://forums.swift.org/t/swift-project-focus-areas-in-2023/61522/1">related discussion</a> on Swift Forums). I just want to highlight two things that could be easily overlooked: The Documentation Workgroup will include guidelines for writing great documentation into the <a href="https://forums.swift.org/t/moving-the-swift-programming-language-book-to-open-source/59989">newly open-sourced</a> “<a href="https://docs.swift.org/swift-book/LanguageGuide/TheBasics.html">The Swift Programming Language</a>” book, which I really appreciate. And the Language Workgroup will publish detailed documentation including guidelines for proposal authors and reviewers, which I think will help get more developers involved in writing or reviewing Evolution proposals in the future. But there’s much more in the article!</p><p>Secondly, Apple has <a href="https://www.swift.org/blog/future-of-foundation/">announced</a> that they are <strong>open-sourcing Foundation</strong>! Okay, not the Foundation code we are using today (which probably has lots of old Obj-C and even wrapped C code anyways), but they are doing the closest thing possible, which is an open-source <em>rewrite</em> of Foundation <em>in Swift</em> which will replace Foundation on Apple platforms in the future. Swift on Server environments will finally get access to all of the same Foundation code.</p><p>They will use this opportunity to properly group things into smaller packages, <code>FoundationEssentials</code> becoming an even slimmer version of today’s Foundation. This way you can skip <code>FoundationInternationalization</code> for non-localized projects or things like XML or networking support where you don’t need them. Also, thanks to a new contribution process, you will not only be able to dig into code if you run into bugs and fix them yourself, but you will also be able to contribute entirely new APIs to Foundation.</p><p>The year 2023 really looks like an exciting year for Swift developers. I’m hyped!</p><blockquote><p>💁🏻‍♂️ <strong>Enjoyed this article? Check out my app <strong>RemafoX</strong>!</strong>
A native Mac app that integrates with Xcode to help translate <strong>your</strong> app.
<a href="https://apps.apple.com/app/apple-store/id1605635026?pt=549314&ct=fline.dev&mt=8&ref=fline.dev"><strong>Get it now</strong></a> to save time during development &amp; make localization easy.</p></blockquote>]]></content:encoded>
<media:thumbnail url="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-december-22/hero.webp"/>
</item>
<item>
<title>Swift Evolution Monthly: October &apos;22</title>
<link>https://evolutionkit.dev/blog/swift-evolution-monthly-october-22/</link>
<guid isPermaLink="true">https://evolutionkit.dev/blog/swift-evolution-monthly-october-22/</guid>
<pubDate>Sun, 30 Oct 2022 00:00:00 +0000</pubDate>
<description><![CDATA[Lifting limitations on Xcode, Result Builder variables, Existential arguments, testable Clocks, and Back-Deploying Functions]]></description>
<content:encoded><![CDATA[<p><img src="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-october-22/hero.webp" alt="Swift Evolution Monthly: October '22" /></p><p>October has been a very busy month for me for two great reasons:</p><p>Firstly, my love for the great country of 🇯🇵 Japan and its people has made me plan for a long-term trip to the country for a long time, and this plan just became a reality this month as <a href="https://en.japantravel.com/guide/japan-s-border-reopening-on-october-11th/69323">Japan reopened its borders</a>. I can look back to a month full of planning, packing, and traveling. The cool thing is: I am actually writing these lines from a <a href="https://goo.gl/maps/SxhxHhNmmyy9mhXH9">café</a> somewhere in Tokyo now, the most populated city on earth! 😍</p><p>I’ll be here <strong>in Japan for the next 3 months</strong>, which is a dream come true for me personally. But don’t worry, I’ll be continuing to work on apps and write articles from here. Just focusing on studying Japanese on top of all else. 🤓</p><p>Secondly, as I already mentioned in the last issue, October was the month I intended to release my first app as an Indie developer – and so I did!</p><p>Say hello to <a href="https://remafox.app/">RemafoX</a>, the app on the mission to <strong>simplify developer life</strong> by providing <strong>new workflows for localization</strong> when working with Xcode. I wrote a short article on how it can help you <a href="https://www.fline.dev/introducing-remafox-easy-app-localization/">here</a> – if you’re very limited on time, make sure to at least watch <a href="https://www.fline.dev/introducing-remafox-easy-app-localization/#previews">these GIFs</a> which will give you a good first impression of it.</p><p>Here’s what other members of the Swift community had to say about it:</p><blockquote><p>This new localisation tool from Cihat Gündüz looks great. As with any tool that tries to integrate with Xcode, setup is a little long-winded and awkward, but once configured, it’s a breeze to add or edit localisations from directly inside your source. The workflow focuses on Xcode, making it an excellent fit for solo developers or small, developer-heavy teams. If that’s you, there’s a free tier/trial, so check it out!</p></blockquote><p>– <a href="https://twitter.com/daveverwer?s=21&t=XKvE300QlWsyA_srkuYZ4w&ref=fline.dev"><strong>Dave Verwer</strong></a> in <a href="https://iosdevweekly.com/issues/580#tools">iOS Dev Weekly</a> (Issue #580)</p><blockquote><p><a href="https://twitter.com/ReMafoX_App">@RemafoX_App</a>, a tool for Indie Developers to localize their iOS apps, looks pretty strong in terms of functionality but it also has fabulous in-app onboarding help and YouTube instructional videos 👍👍👍</p></blockquote><p>– <a href="https://twitter.com/marcoeidinger?s=21&t=tAwcP3HAgw9BRdly4yJhiQ&ref=fline.dev"><strong>Marco Eidinger</strong></a> in <a href="https://twitter.com/marcoeidinger/status/1580069501940408321">this Tweet</a></p><p>Also, I couldn’t have summarized my motivation behind writing this app better than <a href="https://twitter.com/jeehut/status/1582295610170146816">this flattering first US review</a> on the <a href="https://apps.apple.com/us/app/remafox-easy-app-localization/id1605635026">Mac App Store</a>:</p><blockquote><p><strong>Extremely well made &amp; documented</strong>
‌‌I’ve been using this developer’s open-source BartyCrouch localization tool (which) was wonderful but it took ages for me to set up and (learn).
‌‌ReMafoX solves all of those issues extremely well. It’s beautifully designed, well organized, and exceptionally well documented. Every step is explained in detail, both in the code, in the app, and via YouTube videos.</p></blockquote><p>And this is just the beginning. Each month, one new (<a href="https://github.com/FlineDev/ReMafoX/issues?q=is%3Aopen+is%3Aissue+label%3A%22Feature+Request%22+sort%3Areactions-%2B1-desc&ref=fline.dev">requested</a>) feature will be added, the first is <a href="https://remafox.app/changelog/#110--2022-10-29">already out</a> with full support for Ventura and Objective-C files. If you have any localized projects or thought about localizing yours to reach more customers but you found the process too finicky, <a href="https://apps.apple.com/app/apple-store/id1605635026?pt=549314&ct=fline.dev.SEM&mt=8&ref=fline.dev">give ReMafoX a try</a>.</p><p>But enough of my app, let’s get from lifting some of Xcode’s limitations to some interesting new proposals that lift some of Swift’s limitations!</p><h2 id="accepted-proposals">Accepted Proposals</h2><p>The following proposals not yet presented were already <strong>accepted</strong>:</p><h3 id="se-0373-lift-all-limitations-on-variables-in-result-builders">SE-0373: Lift all limitations on variables in result builders</h3><p><strong>Links:</strong> <strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0373-vars-without-limits-in-result-builders.md">Proposal Document</a> 📝 |</strong> <a href="https://forums.swift.org/t/accepted-se-0373-lift-all-limitations-on-variables-in-result-builders/61041">Acceptance Rationale</a> <strong>✅</strong> |<strong><a href="https://forums.swift.org/t/se-0373-lift-all-limitations-on-variables-in-result-builders/60592">Review</a> 🧵</strong></p><p>When writing code in the <code>body</code> of a view in SwiftUI, we can already use a lot of structured programming expressions such as <code>if</code> statements or <code>for-each</code> loops. But we cannot use *everything *that we can use in a function. For example, <code>lazy</code> variables or property wrappers such as <code>@Clamping</code> suggested in <a href="https://nshipster.com/propertywrapper/#implementing-a-value-clamping-property-wrapper">this NSHipster article</a> will work in a function, but not in a SwiftUI <code>body</code>.</p><p>The reason is that SwiftUI has a <a href="https://developer.apple.com/documentation/swiftui/viewbuilder"><code>ViewBuilder</code></a> type, which is a result builder. So all  code you write inside the <code>body</code> runs in a different-than-normal Swift environment, inside the SwiftUI DSL to be exact. This DSL (= domain-specific language) code may look like normal Swift code like we write in a function (thanks to <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0289-result-builders.md">SE-0289</a>), but it actually isn’t. What you can do within result builders is restricted, but this new proposal aims to get rid of some of the restrictions – those on variables in particular. In the future, you will be able to write the following code and it will compile fine (without the error in the comments you currently get):</p><pre><code class="language-Swift">import SwiftUI

struct ContentView: View {
   var body: some View {
      GeometryReader { proxy in
         // ⬇ 'Cannot declare local wrapped variable in builder'
         @Clamping(10...100) var width = proxy.size.width
         Text(&quot;Hello World&quot;).frame(width: width)
      }
   }
}</code></pre><p>‌The full list of removed limitations on variables in result builders is:</p><ul><li><p>Uninitialized variables (e.g. <code>let x: Int</code> – with exceptions like SwiftUI)</p></li><li><p>Default-initialized variables (e.g. <code>var comment: String?</code>)</p></li><li><p>Computed variables (<code>get</code> &amp; <code>set</code>)</p></li><li><p>Observed variables (<code>willSet</code> &amp; <code>didSet</code>)</p></li><li><p>Variables with property wrappers (e.g. <code>@Clamping(1..10) var count = 12</code>)</p></li><li><p><code>lazy</code> variables (e.g. <code>lazy var max: Int = { ... }</code>)</p></li></ul><p>I have not personally wanted to use any of these yet, but I’m glad that more restrictions were lifted for those situations where we actually <em>do</em> need them.</p><h3 id="se-0375-opening-existential-arguments-to-optional-parameters">SE-0375: Opening existential arguments to optional parameters</h3><p><strong>Links:</strong> <strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0375-opening-existential-optional.md">Proposal Document</a> 📝 |</strong> <a href="https://forums.swift.org/t/accepted-se-0375-opening-existential-arguments-to-optional-parameters/61045">Acceptance Rationale</a> <strong>✅</strong> |<strong><a href="https://forums.swift.org/t/se-0375-opening-existential-arguments-to-optional-parameters/60802">Review</a> 🧵</strong></p><p>First, let’s remember that an ‘Existential’ is something like an auto-generated “placeholder box type” when working with variables of a Protocol type – see also my more detailed explanation in the April issue <a href="https://www.fline.dev/swift-evolution-monthly-april-22/#se-0352-implicitly-opened-existentials">here</a>. Now consider this code:</p><pre><code class="language-Swift">func persist&lt;T: Codable&gt;(_ codable: T?, key: String) {
   if let codable {
      storageDict[key] = try! JSONEncoder().encode(codable)
   } else {
      storageDict.removeValue(forKey: key)
   }
}

func valueChanged(value: any Codable, key: String) {
   // ⬇ 'Type 'any Codable' cannot conform to 'Codable''
   persist(value, key: key)
}</code></pre><p>Currently, we get an error when trying to pass the existential <code>any Codable</code> to the <code>persist</code> method which accepts a specific type <code>T</code> that conforms to <code>Codable</code>. Thanks to this new proposal, this will compile in the future as <code>value</code> here is a non-optional and therefore the underlying type can be determined and <code>T</code> is clear.</p><h2 id="proposals-in-reviewrevisionawaiting-decision">Proposals In Review/Revision/Awaiting Decision</h2><blockquote><p><em>Y</em>ou can still provide feedback** for these proposals**. The current <a href="https://apple.github.io/swift-evolution/#?status=rejected">rejection</a> rate is **&lt;<strong>10%, so <strong>they’re</strong>likely <strong>to</strong>get accepted. <a href="https://github.com/apple/swift-evolution/blob/main/process.md#proposal-states">Revisions</a> are more common.</strong></p></blockquote><p>On to new proposals in review/revision/awaiting decision!</p><h3 id="se-0374-add-sleepfor-to-clock">SE-0374: Add sleep(for:) to Clock</h3><p><strong>Links:</strong> <strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0374-clock-sleep-for.md">Proposal Document</a> 📝 | <a href="https://forums.swift.org/t/se-0374-add-sleep-for-to-clock/60787">Review</a> 🧵</strong></p><p>When introducing the new <code>Clock</code>, <code>Instant</code> and <code>Duration</code> types with <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0329-clock-instant-duration.md">SE-0329</a> (see <a href="https://www.fline.dev/swift-evolution-monthly-first-issue/#se-0329-clock-instant-and-duration">my summary</a>), it seems that one important method on the <code>Clock</code> type was forgotten: A <code>sleep(for: Duration)</code> method. This caused a problem when <a href="https://twitter.com/mbrandonw">Brandon Williams</a> and <a href="https://twitter.com/stephencelis">Stephen Celis</a> from <a href="https://www.pointfree.co/">Point-Free</a> used these new APIs to write tests and control time in them for fast unit testing. The reason for their problem was that the existing method <code>sleep(until: Instant)</code> didn’t allow for using an existential clock type to switch out the real-time <code>Clock</code> in tests with a custom fast-forwardable <code>Clock</code> due to the type-erased <code>Instant</code> needed for the <code>sleep(until: Instant)</code> method.</p><p>With this proposal they added a new <code>sleep(for: Duration)</code> method that has no such problem. I’m glad that the community has such great members who play around with new APIs even before they are released so they can already propose a fix to some rough edges before most of us even had a chance to try them out.</p><p>Not only have they fixed the Swift API for us, but they also <a href="https://github.com/pointfreeco/swift-clocks">open-sourced a new library</a> which comes with 3 <code>Clock</code> types included: <code>TestClock</code> for unit tests, <code>ImmediateClock</code> for SwiftUI previews and <code>UnimplementedClock</code> for mocking!</p><h3 id="se-0376-function-back-deployment">SE-0376: Function Back Deployment</h3><p><strong>Links:</strong> <strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0376-function-back-deployment.md">Proposal Document</a> 📝 | <a href="https://forums.swift.org/t/se-0376-function-back-deployment/61015">Review</a> 🧵</strong></p><p>This proposal suggests adding a new <code>@backDeploy(before: ...)</code> attribute to Swift which none of us app or framework developers will ever need. It’s only relevant for those working on system libraries shipped with the OS like <code>SwiftUI</code> or <code>Charts</code>, but this new attribute might still have a big influence on app developers, too:</p><p>Once available, Apple could start introducing new APIs not only for the shiny new operating systems (e.g. <code>iOS 17</code> &amp; <code>macOS 14</code>) but they could also back-deploy <em>some</em> of the new APIs to older OS versions at the same time. App developers then wouldn’t need to do anything specific to use back-deployed functions. Quite the opposite, they will be able to avoid availability checks and fallback code like this:</p><pre><code class="language-Swift">// without back-deployment
if #available(iOS 16.0, *) {
   callSomeShinyNewFunction()
} else {
   // fallback on older systems
}

// with back-deployment
callSomeShinyNewFunction()</code></pre><p>When using a function marked with <code>@backDeploy</code> the compiler will intelligently check the target SDK of the app being built against and if it’s a version that natively supports the new feature, it will use the system framework, mitigating app binary size increases and each app shipping with its own copy of the function.</p><p>Now, don’t get <em>too</em> excited though. While this is really cool and could mean more new APIs will be available to use for teams who need to support OS versions 1-2 years back, there are still limitations. This proposal only discusses adding the attribute for functions, subscripts, and properties without storage. Types like enums and structs or protocol conformances aren’t discussed yet, they are only <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0376-function-back-deployment.md#future-directions">mentioned</a> as potential future directions.</p><p>Also, there are <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0376-function-back-deployment.md#restrictions-on-declarations-that-may-be-back-deployed">restrictions</a> on which functions <em>can</em> be back-deployed, such as that they need to be statically dispatchable (e.g. <code>final</code>), which excludes all functions that are marked to be compatible with Objective-C via <code>@objc</code>. This means that it will be easier for Apple to back-deploy APIs in newer Swift-only frameworks like <code>SwiftUI</code>, <code>Combine</code> or <code>Charts</code> than it will be to do so with older Objective-C-based frameworks like <code>UIKit</code> &amp; <code>AppKit</code>. Also, we don’t know how many teams within Apple will make use of this new feature and how far back they will be able to back-deploy. Only time can tell. But it’s exciting to see this topic is getting some love!</p><h3 id="se-0377-borrow-and-take-parameter-ownership-modifiers">SE-0377: <code>borrow</code> and <code>take</code> parameter ownership modifiers</h3><p><strong>Links:</strong> <strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0377-parameter-ownership-modifiers.md">Proposal Document</a> 📝 | <a href="https://forums.swift.org/t/se-0377-borrow-and-take-parameter-ownership-modifiers/61020">Review</a> 🧵</strong></p><p>This proposal gives Swift authors who are highly concerned about the performance of their code fine-grained control over some aspects of <a href="https://en.wikipedia.org/wiki/Automatic_Reference_Counting">Automatic Reference Counting</a>, the memory management feature of Swift. Two new parameter modifiers (like <code>inout</code>) are introduced for that, namely <code>borrow</code> and <code>take</code>.</p><p>The vast majority of app developers won’t need to use these modifiers and should instead trust Swift’s built-in memory management heuristics. For those who are interested, please <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0377-parameter-ownership-modifiers.md#introduction">read the full proposal</a> to fully understand the new modifiers.</p><blockquote><p>📧 <em>To receive future issues via <strong>email</strong>, subscribe to the newsletter <a href="https://se-monthly.flinedev.com/">here</a>.</em></p></blockquote><h2 id="recently-active-pitchesdiscussions">Recently Active Pitches/Discussions</h2><p>Some threads inside the “Evolution” category with activity within the last month I didn’t link yet. I’ll cover them in detail once (and if) they become proposals:</p><ul><li><p><a href="https://forums.swift.org/t/a-possible-vision-for-macros-in-swift/60900">A Possible Vision for Macros in Swift</a></p></li><li><p><a href="https://forums.swift.org/t/allow-stored-properties-in-extensions/60889">Allow stored properties in extensions</a></p></li><li><p><a href="https://forums.swift.org/t/if-let-x-as-t-if-let-x-x-as-t/60922"><code>if let x as? T</code> ↔ <code>if let x = x as? T</code></a></p></li><li><p><a href="https://forums.swift.org/t/enum-case-keypaths/60899">Enum Case KeyPaths</a></p></li><li><p><a href="https://forums.swift.org/t/new-old-idea-enum-case-blocks/60824">Enum Case Blocks</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-2-value-and-type-parameter-packs/60830">Value and Type Parameter Packs</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-attribute-to-silence-deprecation-warnings-for-a-specified-scope/57791">Attribute to silence Deprecation Warnings for a specified scope</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-package-registry-authentication/61047">Package Registry Authentication</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-isolated-function-values-and-sendable/61046">Isolated Function Values and Sendable</a></p></li><li><p><a href="https://forums.swift.org/t/nested-types-in-protocols-and-nesting-protocols-in-types/4291">Nested types in protocols (and nesting protocols in types)</a></p></li></ul><hr /><blockquote><p>✨ Want to see your ad here? Contact me at <a href="mailto:ads@fline.dev">ads@fline.dev</a> to get in touch.</p></blockquote><hr /><h2 id="other-developments-worth-mentioning">Other Developments worth Mentioning</h2><p>The <strong>Language Workgroup</strong> <a href="https://forums.swift.org/t/returning-or-rejecting-all-the-deferred-evolution-proposals/60724">did some clean-up</a> on 6 old proposals with unclear status, of which 3 were returned to discussion and 3 were rejected outright.</p><p><a href="https://twitter.com/slava_pestov">Slava Pestov</a> announced a documentation book series digging into the details of how Swift generics work. If you’re curious about this topic or if you (want to) work on the Swift compiler in general, you might want to read the <a href="https://forums.swift.org/t/compiling-swift-generics-part-i/60898">free PDF posted here</a>.</p><p>In the last issue I had already <a href="https://www.fline.dev/swift-evolution-monthly-september-22/#other-developments-worth-mentioning">mentioned</a> that parts of Swift are rewritten in Swift. But what I had totally missed is that also the parser for the <a href="https://github.com/apple/swift-syntax">SwiftSyntax</a> library is <a href="https://forums.swift.org/t/a-new-swift-parser-for-swiftsyntax/59813">currently being rewritten in Swift</a> to get rid of the need for the C++ library <code>lib_InternalSwiftSyntaxParser</code> in tools like SwiftLint or BartyCrouch. This [<a href="https://forums.swift.org/t/october-update-on-the-new-swift-parser/61071">October update</a> post](https://forums.swift.org/t/october-update-on-the-new-swift-parser/61071) summarizes the progress on this front and <a href="https://twitter.com/simjp?s=21&t=Xf2-wIm34vIjQQfzTa8c8w&ref=fline.dev">JP Simard</a> also shared his experiences with the new parser in the <a href="https://forums.swift.org/t/october-update-on-the-new-swift-parser/61071/2">same thread</a>.</p><p>Speaking of C++ and updates, the <strong>C++ Interoperability Workgroup</strong> has shared their <a href="https://forums.swift.org/t/october-update-on-the-new-swift-parser/61071/2">8-months progress report</a>.</p><p>Lastly, <a href="https://www.linkedin.com/in/simanerush/">Sima Nerush</a>, a student at Reed College, took some time to <a href="https://forums.swift.org/t/swift-mentorship-program-my-journey/60875">write about her experiences and learnings</a> as part of the <a href="https://www.swift.org/mentorship/">Swift Mentorship Program</a> where she helped fix 4 bugs in Swift. If you’re interested in becoming an active contributor to Swift yourself, set yourself a reminder for June next year when interest surveys are likely to reopen. The program is <strong>open to everyone</strong>, not just students!</p><p>And that’s it from my October update!</p><blockquote><p>💁🏻‍♂️ <strong>Enjoyed this article? Check out my app <strong>RemafoX</strong>!</strong>
A native Mac app that integrates with Xcode to help translate <strong>your</strong> app.
<a href="https://apps.apple.com/app/apple-store/id1605635026?pt=549314&ct=fline.dev&mt=8&ref=fline.dev"><strong>Get it now</strong></a> to save time during development &amp; make localization easy.</p></blockquote>]]></content:encoded>
<media:thumbnail url="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-october-22/hero.webp"/>
</item>
<item>
<title>Swift Evolution Monthly: September &apos;22</title>
<link>https://evolutionkit.dev/blog/swift-evolution-monthly-september-22/</link>
<guid isPermaLink="true">https://evolutionkit.dev/blog/swift-evolution-monthly-september-22/</guid>
<pubDate>Thu, 29 Sep 2022 00:00:00 +0000</pubDate>
<description><![CDATA[Conditional Attributes, StaticBigInt, Stable Sorting, Isolated deinit, Work Groups]]></description>
<content:encoded><![CDATA[<p><img src="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-september-22/hero.webp" alt="Swift Evolution Monthly: September '22" /></p><p>After multiple months full of really impactful and fast-paced changes to Swift, such as all the <a href="https://developer.apple.com/videos/play/wwdc2022/110353">improvements to Generics</a>, the introduction of a <a href="https://developer.apple.com/videos/play/wwdc2022/110357">shiny new Regex engine</a>, and kicking off the next chapter of programming with <a href="https://developer.apple.com/videos/play/wwdc2022/110356">distributed actors</a>, things have slowed down a bit in the last two months. This is also the main reason why there was no dedicated monthly issue for August (also, I focused on <a href="https://twitter.com/ReMafoX_App">my first app</a>, which is now scheduled for release on October 11th).</p><p>If you are an app developer, probably none of the new proposals I’m summarizing down below is going to cause a “Wow!” reaction, at least it didn’t do that for me this time. But I tried to still understand and explain the meaning or direction of each proposal without getting into irrelevant details for app developers.</p><p>More interesting topics await you in the Pitches section, which I always sort by my guessed likeliness of interest to the community and limit to a dozen pitches, adding a few more this time as this issue is spanning <em>two</em> months. So if you don’t have much time but you still want to know what might be coming next, try reading some of the pitches. The community is discussing great ideas constantly!</p><h2 id="accepted-proposals">Accepted Proposals</h2><p>The following proposals already presented in the past have been <strong>accepted</strong>:</p><ul><li><p><strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0363-unicode-for-string-processing.md">SE-0363: Unicode for String Processing</a></strong><br /><a href="https://forums.swift.org/t/accepted-se-0363-unicode-for-string-processing/59998">Rationale</a> <strong>✅</strong> | <a href="https://www.fline.dev/swift-evolution-monthly-july-22/#se-0363-unicode-for-string-processing">My Summary</a> 📋</p></li><li><p><strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0365-implicit-self-weak-capture.md">SE-0365: Allow implicit self for weak self, after self is unwrapped</a></strong><br /><a href="https://forums.swift.org/t/accepted-se-0365-allow-implicit-self-for-weak-self-captures-after-self-is-unwrapped/59517">Rationale</a> <strong>✅</strong> | <a href="https://www.fline.dev/swift-evolution-monthly-july-22/#se-0365-allow-implicit-self-for-weak-self-captures-after-self-is-unwrapped">My Summary</a> 📋</p></li></ul><p>On to not yet presented but already accepted proposals!</p><h3 id="se-0367-conditional-compilation-for-attributes">SE-0367: Conditional compilation for attributes</h3><p><strong>Links:</strong> <strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0367-conditional-attributes.md">Proposal Document</a> 📝 |</strong> <a href="https://forums.swift.org/t/accepted-se-0367-conditional-compilation-for-attributes/59756">Acceptance Rationale</a> <strong>✅</strong> |<strong><a href="https://forums.swift.org/t/se-0367-conditional-compilation-for-attributes/59380">Review</a> 🧵</strong></p><p>Conditional compilation is a language feature very much needed when supporting multiple SDKs (e.g. <code>#if os(iOS)</code>) in an app or multiple Swift versions (e.g. <code>#if swift(&gt;=5.6)</code>) in a framework. The most common use case probably is an <code>#if DEBUG</code> for code that we only want to run during development, but not in production (such as additional logging or different API targets or tokens).</p><p>But currently, if you wanted to conditionally use Swift attributes such as <code>@objc</code> or the newer <code>@preconcurrency</code> (for code that was written without Swift Concurrency in mind, see <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0337-support-incremental-migration-to-concurrency-checking.md">SE-0337</a>), you’d have to <strong>duplicate the code</strong> for the entire thing the attribute applies to, such as for an entire type like in this example:</p><pre><code class="language-Swift">#if compiler(&gt;=5.6)
   @preconcurrency
   protocol P: Sendable {
      func f()
      func g()
   }
#else
   protocol P: Sendable {
      func f()
      func g()
   }
#endif</code></pre><p>From Swift 5.8 onwards we will be able to shorten that code to just this:</p><pre><code class="language-Swift">#if hasAttribute(preconcurrency)
   @preconcurrency
#endif
protocol P: Sendable {
   func f()
   func g()
}</code></pre><p>Note the new <code>hasAttribute</code> conditional directive. This not only prevents duplicate code but also more clearly states <em>why</em> we were using a conditional compilation here (because of the attribute!) and <em>saves us the time</em> of having to look up which Swift version the attribute was introduced in.</p><h3 id="se-0368-staticbigint">SE-0368: StaticBigInt</h3><p><strong>Links:</strong> <strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0368-staticbigint.md">Proposal Document</a> 📝 |</strong> <a href="https://forums.swift.org/t/accepted-se-0368-staticbigint/59962">Acceptance Rationale</a> <strong>✅</strong> |<strong><a href="https://forums.swift.org/t/se-0368-staticbigint/59421">Review</a> 🧵</strong></p><p>Unless you’re working on a mathematical app or framework, you probably won’t need to know about the new <code>StaticBigInt</code> type introduced here. But if you do, you might want to read the full proposal (it’s short enough) to learn how you can define your own large integer types that support literals that don’t fit into <code>[U]Int64</code>.</p><p>Maybe also worth noting that the official <a href="https://github.com/apple/swift-numerics">swift-numerics</a> library might soon get <a href="https://github.com/apple/swift-numerics/issues/4">larger integer types</a> such as <code>[U]Int256</code> once this was accepted.</p><h3 id="se-0369-add-customdebugstringconvertible-conformance-to-anykeypath">SE-0369: Add CustomDebugStringConvertible conformance to AnyKeyPath</h3><p><strong>Links:</strong> <strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0369-add-customdebugdescription-conformance-to-anykeypath.md">Proposal Document</a> 📝 |</strong> <a href="https://forums.swift.org/t/accepted-se-0369-add-customdebugstringconvertible-conformance-to-anykeypath/60001">Acceptance Rationale</a> <strong>✅</strong> |<strong><a href="https://forums.swift.org/t/se-0369-add-customdebugstringconvertible-conformance-to-anykeypath/59704">Review</a> 🧵</strong></p><p>This proposal aims at improving the <code>print</code>ing of key paths such as in <code>print(\User.name)</code> from currently resulting in <code>Swift.KeyPath&lt;User, String&gt;</code> which is not very useful, to result in something closer to the call like <code>\User.name</code>.</p><p>This small improvement could help in debugging and make unit tests clearer.</p><h3 id="se-0370-pointer-family-initialization-improvements-and-better-buffer-slices">SE-0370: Pointer Family Initialization Improvements and Better Buffer Slices</h3><p><strong>Links:</strong> <strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0370-pointer-family-initialization-improvements.md">Proposal Document</a> 📝 |</strong> <a href="https://forums.swift.org/t/accepted-se-0370-pointer-family-initialization-improvements-and-better-buffer-slices/60007">Acceptance Rationale</a> <strong>✅</strong> |<strong><a href="https://forums.swift.org/t/se-0370-pointer-family-initialization-improvements-and-better-buffer-slices/59724">Review</a> 🧵</strong></p><p>This is a low-level programming improvement that is not relevant for most app developers. For those interested in low-level, the title should clarify the topic.</p><h3 id="se-0372-document-sorting-as-stable">SE-0372: Document Sorting as Stable</h3><p><strong>Links:</strong> <strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0372-document-sorting-as-stable.md">Proposal Document</a> 📝 |</strong> <a href="https://forums.swift.org/t/accepted-se-0372-document-sorting-as-stable/60425">Acceptance Rationale</a> <strong>✅</strong> |<strong><a href="https://forums.swift.org/t/se-0372-document-sorting-as-stable/60165">Review</a> 🧵</strong></p><p>Imagine you have an array of books in code, something like this:</p><pre><code class="language-Swift">var books: [Book] = [
   .init(author: &quot;Robert Galbraith&quot;, title: &quot;The Cuckoo's Calling&quot;),
   .init(author: &quot;J. R. R. Tolkien&quot;, title: &quot;The Fellowship of the Ring&quot;),
   .init(author: &quot;J. R. R. Tolkien&quot;, title: &quot;The Two Towers&quot;),
   .init(author: &quot;J. R. R. Tolkien&quot;, title: &quot;The Return of the King&quot;),
]</code></pre><p>And you call <code>books.sort(by: { $0.author &lt; $1.author })</code>, you would expect that the three Lord of the Rings books from J. R. R. Tolkien would be sorted above the first Cormoran Strike book by J. K. Rowling, right? You’re right, of course.</p><p>But would you also expect the three Lord of the Rings books to remain in the right order, starting with “The Fellowship of the Ring”? I guess you would. It’s how humans would naturally sort. But technically speaking, all three Lord of the Rings books have the same author, and therefore the sorting criteria treats them all like they’re on the same level. How elements that are on the same level are treated depends on the sorting algorithm. Algorithms that <em>preserve</em> the order of equal-level elements are called “stable”.</p><p>In Swift, the <code>sort</code> function has been implemented as a “stable” algorithm for multiple years now, but it was never documented to be. So in theory, the implementation of future versions could have changed to a non-stable algorithm. Not anymore: This proposal documents the <code>sort</code> function’s behavior to be stable.</p><h2 id="proposals-in-reviewrevisionawaiting-decision">Proposals In Review/Revision/Awaiting Decision</h2><blockquote><p><em>Y</em>ou can still provide feedback** for these proposals**. The current <a href="https://apple.github.io/swift-evolution/#?status=rejected">rejection</a> rate is **&lt;<strong>10%, so <strong>they’re</strong>likely <strong>to</strong>get accepted. <a href="https://github.com/apple/swift-evolution/blob/main/process.md#proposal-states">Revisions</a> are more common.</strong></p></blockquote><p>These proposals already presented in the past were <strong>returned for revision</strong>:</p><ul><li><p><strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0364-retroactive-conformance-warning.md">SE-0364: Warning for Retroactive Conformance of External Types</a></strong><br />[<a href="https://forums.swift.org/t/accepted-se-0363-unicode-for-string-processing/59998">Rationale</a>](https://forums.swift.org/t/returned-for-revision-se-0364-warning-for-retroactive-conformance-of-external-types/59729) *🔁 | *<a href="https://www.fline.dev/swift-evolution-monthly-july-22/#se-0364-warning-for-retroactive-conformances-of-external-types">My Summary</a> 📋</p></li><li><p>[<strong><a href="https://forums.swift.org/t/returned-for-revision-se-0366-move-operation-use-after-move-diagnostic/59687">SE-0366: Move Operation + “Use After Move” Diagnostic</a></strong>](https://github.com/apple/swift-evolution/blob/main/proposals/0366-move-function.md)<br /><a href="https://forums.swift.org/t/returned-for-revision-se-0366-move-operation-use-after-move-diagnostic/59687">Rationale</a> *🔁 | *<a href="https://www.fline.dev/swift-evolution-monthly-july-22/#se-0366-move-function-%E2%80%9Cuse-after-move%E2%80%9D-diagnostic">My Summary</a> 📋</p></li></ul><p>On to new proposals in review/revision/decision!</p><h3 id="se-0371-isolated-synchronous-deinit">SE-0371: Isolated synchronous deinit</h3><p><strong>Links:</strong> **<a href="https://github.com/apple/swift-evolution/blob/main/proposals/0371-isolated-synchronous-deinit.md"><strong>Proposal Document</strong></a>**📝 | **<a href="https://forums.swift.org/t/se-0371-isolated-synchronous-deinit/59754"><strong>Review</strong></a><strong>🧵</strong> | <a href="https://forums.swift.org/t/returned-for-revision-se-0371-isolated-synchronous-deinit/60060">Revision Rationale</a> 🔁</p><p>This proposal is another one that probably won’t sound like a huge deal to most app developers. Especially because most didn’t have the chance to make full use of <code>actor</code> types yet (including myself). Introduced with <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0306-actors.md">SE-306</a> in Swift 5.5, they help deal with concurrently executed logic that “acts” on the same data in parallel. A good sign that you should probably consider using them more is when you have classes as data models in your app. Chances are that you might be accessing them simultaneously. And migrating them over to <code>actor</code> types should be possible, given that actors are also reference types like <code>class</code>es.</p><p>In Swift, it’s common for types that hold onto other data or dependencies to automatically get rid of these in a <code>deinit</code> method, rather than requiring a <code>close()</code> like method that needs to be explicitly called. When initializers were settled in the Swift actor world with <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0327-actor-initializers.md">SE-0237</a>, the deinitializer’s access <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0327-actor-initializers.md#deinitializers">was limited</a> to <code>Sendable</code> stored properties only. All value types ( <code>enum</code>s, <code>struct</code>s) and all <em>immutable</em> reference types ( <code>class</code>es) can be easily marked as <code>Sendable</code>, which means the data is safe to pass across threads. This proposal weakens that limitation by being smart about the details of the state without compromising safety. This allows a <code>deinit</code> function to additionally access some <strong>non</strong>- <code>Sendable</code> state, preventing the need of having to provide a <code>close()</code> function or do internal reference counting.</p><p>While I don’t fully understand this proposal’s impact even after reading it twice, it sounds a lot like a “rounding things off” kind of proposal to me, which we will all appreciate once we got more used to writing <code>actor</code> types. Currently, I guess, it mostly affects Server-side Swift developers and lower-level framework authors.</p><blockquote><p>📧 <em>To receive future issues via <strong>email</strong>, subscribe to the newsletter <a href="https://se-monthly.flinedev.com/">here</a>.</em></p></blockquote><h2 id="recently-active-pitchesdiscussions">Recently Active Pitches/Discussions</h2><p>Some threads inside the “Evolution” category with activity within the last 2 months I didn’t link yet. I’ll cover them in detail once (and if) they become proposals:</p><ul><li><p><a href="https://forums.swift.org/t/pre-pitch-explicit-protocol-fulfilment-with-the-conformance-keyword/60246">Explicit protocol fulfilment with the ‘conformance’ keyword</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-parameter-packs/60543">Parameter Packs</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-one-element-tuples/60219">One-Element Tuples</a></p></li><li><p><a href="https://forums.swift.org/t/a-new-keyword-that-stands-in-for-a-tedious-initializer-of-arbitrary-length/60173">A new keyword that stands in for a tedious initializer of arbitrary length</a></p></li><li><p><a href="https://forums.swift.org/t/optional-explicit-self-parameter-declaration-in-methods/59522">Optional explicit <code>self</code> parameter declaration in methods</a></p></li><li><p><a href="https://forums.swift.org/t/allow-opaque-result-types-in-protocol-requirements/59926">Allow opaque result types in protocol requirements</a></p></li><li><p><a href="https://forums.swift.org/t/build-time-sdk-availability-check/59679">Build-time SDK availability check</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-pointer-bit-width-compile-time-conditional/59572">Pointer bit width compile time conditional</a></p></li><li><p><a href="https://forums.swift.org/t/evolution-idea-implicit-return-in-single-line-switch-cases/59684">Implicit return in single-line switch cases</a></p></li><li><p><a href="https://forums.swift.org/t/allow-package-swift-to-not-be-at-the-root-of-the-repository/60431">Allow Package.swift to not be at the root of the repository</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-clock-sleep-for/60376">clock.sleep(for:)</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-add-equatable-and-hashable-conformance-to-string-views/60449">Add Equatable and Hashable conformance to String views</a></p></li><li><p><a href="https://forums.swift.org/t/selective-control-of-implicit-copying-behavior-take-borrow-and-copy-operators-noimplicitcopy/60168">Selective control of implicit copying behavior: <code>take</code>, <code>borrow</code>, <code>copy</code></a></p></li><li><p><a href="https://forums.swift.org/t/mini-pitch-for-se-0352-amendment-allow-opening-an-existential-argument-to-an-optional-parameter/60501">Allow opening an existential argument to an optional parameter</a></p></li><li><p><a href="https://forums.swift.org/t/template-for-a-possible-future-object-model/59823">Template for a possible future object model</a></p></li></ul><hr /><blockquote><p>✨ Want to see your ad here? Contact me at <a href="mailto:ads@fline.dev">ads@fline.dev</a> to get in touch.</p></blockquote><hr /><h2 id="other-developments-worth-mentioning">Other Developments worth Mentioning</h2><p>It’s great to see that there are <a href="https://forums.swift.org/t/implementing-parts-of-the-swift-compiler-in-swift/59524">plans to implement parts of the Swift compiler <em>in Swift</em></a> (I know, it sounds like an infinite recursion to use Swift for Swift, but it works because the latest <em>development</em> Swift is built with the latest <em>stable release</em> Swift, which was at some point built without any Swift involved [mostly C++]).</p><p>The 6 currently existing workgroups (<a href="https://www.swift.org/language-workgroup/">Language</a>, <a href="https://www.swift.org/cxx-interop-workgroup/">C++ Interoperability</a>, <a href="https://www.swift.org/sswg/">Server</a>, <a href="https://www.swift.org/website-workgroup/">Swift.org website</a>, <a href="https://www.swift.org/documentation-workgroup/">Documentation</a>, and <a href="https://www.swift.org/diversity/">Diversity</a>) might soon be joined by new groups: Besides <a href="https://forums.swift.org/t/formalizing-a-numerical-ml-working-group/45553/1">Numerical/ML</a> mentioned in the May issue already, one for <a href="https://forums.swift.org/t/pitch-swift-tooling-workgroup/59515">Swift Tooling</a> and one for broader <a href="https://forums.swift.org/t/initiative-swift-platform-work-group/60340">Platform Support</a> were recently discussed. I also found an older discussion about an <a href="https://forums.swift.org/t/call-for-interest-video-call-kickoff-using-swift-for-embedded-bare-metal-low-resources-programming/56911">Embedded/Bare Metal/Low Resources</a> group. All of these groups make a lot of sense to me, so I hope they will be successful!</p><p>That’s it from my September update!</p><blockquote><p>💁🏻‍♂️ <strong>Enjoyed this article? Check out my app <strong>RemafoX</strong>!</strong>
A native Mac app that integrates with Xcode to help translate <strong>your</strong> app.
<a href="https://apps.apple.com/app/apple-store/id1605635026?pt=549314&ct=fline.dev&mt=8&ref=fline.dev"><strong>Get it now</strong></a> to save time during development &amp; make localization easy.</p></blockquote>]]></content:encoded>
<media:thumbnail url="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-september-22/hero.webp"/>
</item>
<item>
<title>Swift Evolution Monthly: July &apos;22</title>
<link>https://evolutionkit.dev/blog/swift-evolution-monthly-july-22/</link>
<guid isPermaLink="true">https://evolutionkit.dev/blog/swift-evolution-monthly-july-22/</guid>
<pubDate>Wed, 03 Aug 2022 00:00:00 +0000</pubDate>
<description><![CDATA[My first Indie App, my first Evolution pitch experience, the last of 6 Regex proposals, external conformance warning, implicit [weak self] capture & a new 'move' keyword.]]></description>
<content:encoded><![CDATA[<p><img src="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-july-22/hero.webp" alt="Swift Evolution Monthly: July '22" /></p><p>Here we are again with another monthly summary of Swift Evolution. July was a very special month for me, so I’d like to start with two topics that are important to me personally. I hope you’ll excuse that – but both are still on-topic:</p><p>Firstly, my very first app as an Indie Developer, which I’ve been working on for six months now, is finally done and in <a href="https://github.com/FlineDev/ReMafoX/releases">Open Beta</a>! It’s an app for Swift developers and <strong>improves the localization workflow</strong> in Xcode. In the first version, among other things, you can add new localized keys to your projects in multiple languages without ever leaving your Swift file and safely reference them in code – just by filling out a single form! The app will take care of adding entries to all the right files and even optionally machine-translate to multiple languages, see <a href="https://twitter.com/Jeehut/status/1545038020218200065">this GIF</a>:</p><p><a href="https://twitter.com/Jeehut/status/1545038020218200065"><img src="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-july-22/a-gif-showing-how-you.gif" alt="" loading="lazy" /></a></p><p><em>A GIF showing how you can add a new key to your app with RemafoX.</em></p><p>If this looks interesting to you, please <a href="https://github.com/FlineDev/ReMafoX/releases/download/1.0.0-beta.1/ReMafoX.app.zip">try the beta</a> and send me your feedback.</p><p>Secondly, one day after sending out the previous issue of this newsletter, I wrote my very <a href="https://forums.swift.org/t/if-guard-let-catch-for-conveniently-accessing-both-result-type-cases/58492">first own Swift Evolution pitch</a>. In the thread, I’m requesting a new syntax to improve the usage of the <code>Result</code> type as an alternative for Swift’s native error handling. In the above-mentioned app project, I preferred to have typed errors in order to vastly improve my error handling experience by forcing me to handle all possible error cases with a useful message. But Swift currently doesn’t support typed throws, so I used <code>Result</code> instead and migrated all my throwing functions in the above-mentioned app to it. I’ll be writing about my approach in detail soon on my <a href="https://www.fline.dev/tag/dev-blog/">dev blog</a> if you’re interested. But I came across two safety &amp; convenience issues that I couldn’t fix without changes in the language itself. Thus, <a href="https://forums.swift.org/t/if-guard-let-catch-for-conveniently-accessing-both-result-type-cases/58492">the pitch</a>.</p><p>If my pitch sounds like something you’d want to have in Swift, don’t get too excited though. Even though I tried to scope it clearly and I tried to make the change as small and language-fitting as possible, I quickly received a lot of refusing comments due to historical discussions on typed <code>throw</code>s, even though my pitch is just about <em>adding convenience &amp; safety</em> to <code>Result</code> – to improve things already possible in Swift <em>today</em>. In fact, the topic of typed <code>throw</code>s seems to be one of the most controversial topics on Swift Evolution, which I learned the hard way in this thread. This was not the great first-pitch experience on Swift Evolution that I was hoping for to write about in this issue of the newsletter.</p><p>Thankfully, after <a href="https://forums.swift.org/t/if-guard-let-catch-for-conveniently-accessing-both-result-type-cases/58492/20">explaining my specific use case</a> and <a href="https://forums.swift.org/t/if-guard-let-catch-for-conveniently-accessing-both-result-type-cases/58492/21">clarifying that my intention was not to rehash any historical discussions</a>, the topic of the thread changed from a judging “there’s no problem in the language, you’re just using it wrong” to a more accepting “let’s explore how we can improve the valid use case you described” kind of vibe. I hope it stays like that and even more, I wish it was like that from the start. It’s hard for me to motivate anyone in the developer community to be more active in the forums with their own pitches if I have to add to that that they should be cautious not to run into some of the difficult topics. But here we are.</p><p>I’m sure, the whole thing was a misunderstanding and I probably didn’t communicate things clearly enough on my end. But in any case, this is a good opportunity to remind everyone (including me!) to always initially expect others to have good intentions and to respect the decisions they made for themselves. This is much better than expecting the worst and judging their decisions by making assumptions about their situation based on your own past experiences. It might be tempting to do that sometimes as it can simplify your life, but it’s not always right and can even hurt people. After all, people are different, situations are different, therefore solutions will always be different, too. A “general purpose language” like Swift and the community around it should accommodate that.</p><p>With this longer comment this time, let’s get on to this month’s proposals!</p><h2 id="accepted-proposals">Accepted Proposals</h2><p>The following proposals already presented in the past have been <strong>accepted</strong>:</p><ul><li><p><strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0351-regex-builder.md">SE-0351: Regex Builder DSL</a></strong>
<a href="https://forums.swift.org/t/accepted-se-0351-regex-builder-dsl/58972">Rationale</a> ✅ | <a href="https://www.fline.dev/swift-evolution-monthly-april-22/#se-0351-regex-builder-dsl">My Summary</a> 📋</p></li><li><p><strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0354-regex-literals.md">SE-0354: Regex Literals</a></strong>
<a href="https://forums.swift.org/t/accepted-with-modifications-se-0354-regex-literals/58537">Rationale</a> ✅ | <a href="https://www.fline.dev/swift-evolution-monthly-may-22/#se-0354-regex-literals">My Summary</a> 📋</p></li><li><p><strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0355-regex-syntax-run-time-construction.md">SE-0355: Regex Syntax &amp; Runtime Construction</a></strong>
<a href="https://forums.swift.org/t/accepted-se-0355-regex-syntax-and-runtime-construction/59232">Rationale</a> ✅ | <a href="https://www.fline.dev/swift-evolution-monthly-may-22/#se-0355-regex-syntax-and-run-time-construction">My Summary</a> 📋</p></li><li><p><strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0357-regex-string-processing-algorithms.md">SE-0357: Regex-powered string processing algorithms</a></strong>
<a href="https://forums.swift.org/t/accepted-with-modifications-se-0357-regex-string-processing-algorithms/58706">Rationale</a> ✅ | <a href="https://www.fline.dev/swift-evolution-monthly-may-22/#se-0357-regex-powered-string-processing-algorithms">My Summary</a> 📋</p></li><li><p><strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0358-primary-associated-types-in-stdlib.md">SE-0358: Primary Associated Types in the Standard Library</a></strong>
<a href="https://forums.swift.org/t/accepted-se-0358-primary-associated-types-in-the-standard-library/58547">Rationale</a> ✅ | <a href="https://www.fline.dev/swift-evolution-monthly-may-22/#se-0358-primary-associated-types-in-the-standard-library">My Summary</a> 📋</p></li><li><p><strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0360-opaque-result-types-with-availability.md">SE-0360: Opaque result types with limited availability</a></strong>
<a href="https://forums.swift.org/t/accepted-se-0360-opaque-result-types-with-limited-availability/58712">Rationale</a> ✅ | <a href="https://www.fline.dev/swift-evolution-monthly-june-22/#se-0360-opaque-result-types-with-limited-availability">My Summary</a> 📋</p></li><li><p><strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0361-bound-generic-extensions.md">SE-0361: Extensions on bound generic types</a></strong>
<a href="https://forums.swift.org/t/accepted-se-0361-extensions-on-bound-generic-types/58716">Rationale</a> ✅ | <a href="https://www.fline.dev/swift-evolution-monthly-june-22/#se-0361-extensions-on-bound-generic-types">My Summary</a> 📋</p></li><li><p><strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0362-piecemeal-future-features.md">SE-0362: Piecemeal adoption of upcoming language improvements</a></strong>
<a href="https://forums.swift.org/t/accepted-se-0362-piecemeal-adoption-of-future-language-improvements/59076">Rationale</a> ✅ | <a href="https://www.fline.dev/swift-evolution-monthly-june-22/#se-0362-piecemeal-adoption-of-future-language-improvements">My Summary</a> 📋</p></li></ul><h2 id="proposals-in-reviewawaiting-decision">Proposals In Review/Awaiting Decision</h2><blockquote><p><em>You can still provide feedback for these proposals. The current <a href="https://apple.github.io/swift-evolution/#?status=rejected">rejection</a> rate is &lt;10%, so they’re likely to get accepted. <a href="https://github.com/apple/swift-evolution/blob/main/process.md#proposal-states">Revisions</a> are more common.</em></p></blockquote><p>The following proposals already presented were <strong>returned for revision</strong>:</p><ul><li><p><strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0359-build-time-constant-values.md">SE-0359: Build-Time Constant Values</a></strong>
<a href="https://forums.swift.org/t/returned-for-revision-se-0359-build-time-constant-values/58976">Rationale</a> 🔄 | <a href="https://forums.swift.org/t/se-0359-build-time-constant-values/57562">Review</a> 🧵 | <a href="https://www.fline.dev/swift-evolution-monthly-june-22/#se-0359-build-time-constant-values">My Summary</a> 📋</p></li></ul><p><strong>On to new proposals currently in review (or still awaiting a decision)!</strong></p><h3 id="se-0363-unicode-for-string-processing">SE-0363: Unicode for String Processing</h3><p><strong>Links:</strong> <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0363-unicode-for-string-processing.md">Proposal Document</a> 📝 | <a href="https://forums.swift.org/t/se-0363-unicode-for-string-processing/58520">Review</a> 🧵</p><p>This is the last of the six <a href="https://github.com/apple/swift-experimental-string-processing/blob/main/Documentation/Evolution/ProposalOverview.md">Regex String-Processing</a> proposals that were explored with the <a href="https://github.com/apple/swift-experimental-string-processing">swift-experimental-string-processing</a> package on GitHub before they were turned into a set of proposals. I covered them all in past issues (<a href="https://www.fline.dev/swift-evolution-monthly-april-22/#se-0350-regex-type-and-overview">1</a>, <a href="https://www.fline.dev/swift-evolution-monthly-april-22/#se-0351-regex-builder-dsl">2</a>, <a href="https://www.fline.dev/swift-evolution-monthly-may-22/#se-0354-regex-literals">3</a>, <a href="https://www.fline.dev/swift-evolution-monthly-may-22/#se-0355-regex-syntax-and-run-time-construction">4</a>, <a href="https://www.fline.dev/swift-evolution-monthly-may-22/#se-0357-regex-powered-string-processing-algorithms">5</a>) and they were all accepted already. Some of them have shipped as part of the Xcode 14 betas, it’s worth mentioning this year’s WWDC sessions <a href="https://developer.apple.com/videos/play/wwdc2022/110357">Meet Swift Regex</a> &amp; <a href="https://developer.apple.com/videos/play/wwdc2022/110358">Swift Regex: Beyond the basics</a> again as they provide a great introduction to the topic.</p><p>This last proposal explains all the details of how Swifts Regex engine supports Unicode by default, which is not the case for many Regex engines. It also goes into the details of how character classes (which can be thought of as a Swift-native version of <a href="https://developer.apple.com/documentation/foundation/characterset">Foundations <code>CharacterSet</code> class</a>) such as <code>.digit</code>, <code>.whitespace</code> and <code>.wordCharacter</code> are defined and how you can adjust them to fit your needs.</p><p>Here are a few key points worth pointing out:</p><ul><li><p>Swift will do “<a href="https://docs.swift.org/swift-book/LanguageGuide/StringsAndCharacters.html#ID296">grapheme cluster</a> matching” by default in its Regex engine – this means that the Regex <code>Caf.</code> (the <code>.</code> matching “any” single character) will match <code>Café</code> always correctly – unlike e.g. C#, Rust, Go, Python, Objective-C, Java<a href="https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html#CANON_EQ">*</a>, Ruby, and Perl which would just match <code>Cafe</code> without the <a href="https://en.wikipedia.org/wiki/Acute_accent">acute accent</a> on top of the “e” for an <code>é</code> that consists of multiple Unicode scalars ( <code>&quot;\u{65}\u{301}&quot;</code>).</p></li><li><p>If you need “Unicode scalar” level matching semantics (e.g. for compatibility):</p></li></ul><pre><code class="language-Swift">&quot;Café&quot;.contains(/Café/.matchingSemantics(.unicodeScalar)) // =&gt; false</code></pre><ul><li><p>By default, the grouping of characters into character classes follows the modern <a href="https://unicode.org/reports/tr18/">Unicode Technical Standard #18</a>. But custom matching behaviors can be provided, such as <code>.ignoresCase()</code>, <code>dotMatchesNewlines()</code>, <code>anchorsMatchNewlines()</code>, and <code>asciiOnlyClasses()</code>. Advanced Regex users might find <code>[defaultRepetitionBehavior()](https://github.com/apple/swift-evolution/blob/main/proposals/0363-unicode-for-string-processing.md#eagerreluctant-toggle)</code> very handy.</p></li><li><p>The available character classes are: <code>.any</code> (= <code>.</code>), <code>.anyNonNewline</code> (= <code>.</code>), <code>.anyGraphemeCluster</code> (= <code>\X</code>), <code>.digit</code> (= <code>\d</code>), <code>.hexDigit</code>, <code>.word</code> (= <code>\w</code>),  <code>.whitespace</code> (= <code>\s</code>), <code>.horizontalWhitespace</code> (= <code>\h</code>), <code>.verticalWhitespace</code> (= <code>\v</code>), <code>.newlineSequence</code> (= <code>\n</code> or <code>\R</code>).</p></li><li><p>Character classes can be inverted, for example:<br /><code>.digit.inverted</code> (= <code>\D</code>) and <code>.word.inverted</code> (= <code>\W</code>)</p></li><li><p>Like with <a href="https://developer.apple.com/documentation/foundation/characterset">Foundations <code>CharacterSet</code> class</a>, you can build a <code>union</code> or <code>intersection</code> of two character classes or you can be  <code>subtracting</code> one from another and even build their <code>symmetricDifference</code>. You can also specify custom classes with the <code>.anyOf</code> and <code>noneOf</code> static methods. For example:</p></li></ul><pre><code class="language-Swift">let floatingNumber: CharacterClass = .digit.union(.anyOf(&quot;.,&quot;))</code></pre><h3 id="se-0364-warning-for-retroactive-conformances-of-external-types">SE-0364: Warning for Retroactive Conformances of External Types</h3><p><strong>Links:</strong> <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0364-retroactive-conformance-warning.md">Proposal Document</a> 📝 | <a href="https://forums.swift.org/t/se-0364-warning-for-retroactive-conformances-of-external-types/58922">Review</a> 🧵</p><p>Do you have code in your projects that extends a type from Apple or Swifts standard library to make them conform to the likes of <code>Equatable</code>, <code>Identifiable</code>, <code>Hashable</code>, or <code>Codable</code>? Did you know that it is discouraged to extend external types with custom conformances to these protocols? The reason is that in case Apple or the Swift community decides to add conformance to the type in the original framework, it’s currently undefined which of the two implementations (yours or the frameworks) will be used, which can lead to unexpected behavior in your app. Note that this is only a problem for users who upgrade to a newer version of the OS but have a version of your app installed that you have not built with the new version of Xcode.</p><p>In my current project, I did a quick search on the left sidebar “Find -&gt; Regular Expression” by pasting <code>extension \w+: (Equatable|Identifiable|Hashable|Codable)</code> and I found this extension, which I need because I use <a href="https://github.com/pointfreeco/swift-composable-architecture">TCA</a> which requires my view state types to be <code>Equatable</code>, and I need a <code>Binding</code> in some of them:</p><pre><code class="language-Swift">extension Binding: Equatable where Value: Equatable {
   public static func == (left: Binding&lt;Value&gt;, right: Binding&lt;Value&gt;) -&gt; Bool {
      left.wrappedValue == right.wrappedValue
   }
}</code></pre><p>This proposal suggests showing a warning in all places where you are extending an external type with these kinds of conformances. The idea is to make developers more aware of this potential issue and convince them to re-consider conforming an external type. To silence the warning you would add the module name in front of each involved type explicitly like so (note the <code>SwiftUI.</code> and <code>Swift.</code> prefixes):</p><pre><code class="language-Swift">extension SwiftUI.Binding: Swift.Equatable where Value: Swift.Equatable {
   public static func == (left: SwiftUI.Binding&lt;Value&gt;, right: SwiftUI.Binding&lt;Value&gt;) -&gt; Bool {
      left.wrappedValue == right.wrappedValue
   }
}</code></pre><h3 id="se-0365-allow-implicit-self-for-weak-self-captures-after-self-is-unwrapped">SE-0365: Allow implicit self for weak self captures, after self is unwrapped</h3><p><strong>Links:</strong> <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0365-implicit-self-weak-capture.md">Proposal Document</a> 📝 | <a href="https://forums.swift.org/t/se-0365-allow-implicit-self-for-weak-self-captures-after-self-is-unwrapped/59040">Review</a> 🧵</p><p>Since Swift 5.3 it is possible to write a closure and capture <code>[self]</code> in order to not have to write <code>self.</code> in front of every call on properties and functions of the current type within the body of the closure (thanks to <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0269-implicit-self-explicit-capture.md">SE-0269</a>) like this:</p><pre><code class="language-Swift">button.tapHandler = { [self] in
   dismiss()  // no need to write `self.dismiss()`
}</code></pre><p>This proposal aims to introduce this same behavior for <code>[weak self]</code> as well when and only after the <code>Optional</code> of <code>self</code> is unwrapped. So for example a <code>guard let self = self else { return }</code> (or the <a href="https://www.fline.dev/swift-evolution-monthly-first-issue/#se-0345-if-let-shorthand-for-shadowing-an-existing-optional-variable">newly possible</a> <code>guard let self { return }</code>) would make <code>self.</code> calls for properties and functions unnecessary:</p><pre><code class="language-Swift">button.tapHandler = { [weak self] in
   guard let self { return }
   dismiss()  // no need to write `self.dismiss()`
}</code></pre><h3 id="se-0366-move-function-use-after-move-diagnostic">SE-0366: Move Function + “Use After Move” Diagnostic</h3><p><strong>Links:</strong> <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0366-move-function.md">Proposal Document</a> 📝 | <a href="https://forums.swift.org/t/se-0366-move-function-use-after-move-diagnostic/59202">Review</a> 🧵</p><blockquote><p>ℹ️ UPDATE: The <code>move</code> keyword was renamed to <code>consume</code> after reviews.</p></blockquote><p>This proposal adds a new <code>move</code> keyword that gives developers of performance-sensitive code more fine-grained control over when a variable or parameter should be released from memory. The compiler will then ensure a “moved” variable or parameter is no longer accidentally used unless a new value is reassigned to it explicitly. Most app developers won’t ever need to use this keyword, but for those interested here’s a function demonstrating the use of the <code>move</code> keyword:</p><pre><code class="language-Swift">func f(inout x: Int = 5) -&gt; Int {
   print(x)  // =&gt; &quot;5&quot;
   
   let y = move x + 1
   print(x)  // error: 'x' used after being moved
   print(y)  // =&gt; &quot;6&quot;
   
   var z = move y
   print(y)  // error: 'y' used after being moved
   print(z)  // =&gt; &quot;6&quot;
   
   move z
   print(z)  // error: 'z' used after being moved
   
   z = 10
   print(z)  // =&gt; &quot;10&quot; (reassigned a new value to 'z', no error)
   
   x = z
   print(x)  // =&gt; &quot;10&quot; (reassigned a new value to 'x', no error)
   
   return z
}</code></pre><h2 id="recently-active-pitchesdiscussions">Recently Active Pitches/Discussions</h2><p>Some threads inside the “Evolution” category with activity within the last month I didn’t link yet. I’ll cover them in detail once (and if) they become proposals:</p><ul><li><p><a href="https://forums.swift.org/t/unit-tests-in-source-code/59160">Unit Tests in Source Code</a></p></li><li><p><a href="https://forums.swift.org/t/music-dsl-similar-to-regex-for-music-notation/58592">Music DSL (similar to Regex) for Music Notation</a></p></li><li><p><a href="https://forums.swift.org/t/if-guard-let-catch-for-conveniently-accessing-both-result-type-cases/58492">If/guard-let-catch for conveniently accessing both Result type cases</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-attribute-to-silence-deprecation-warnings-for-a-specified-scope/57791">Attribute to silence Deprecation Warnings for a specified scope</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-pass-through-initializers-for-enum-associated-values/59373">Pass-through initializers for enum associated values</a></p></li><li><p><a href="https://forums.swift.org/t/zero-sized-types-vs-tuple-memory-layout/58768">Zero-sized types vs tuple memory layout</a></p></li><li><p><a href="https://forums.swift.org/t/should-clock-sleep-for-be-added/58568">Should Clock.sleep(for:) be added?</a></p></li><li><p><a href="https://forums.swift.org/t/approaches-for-fixed-size-arrays/58894">Approaches for fixed-size arrays</a></p></li><li><p><a href="https://forums.swift.org/t/make-it-easier-to-share-state/58471">Make it easier to share state</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-3-opt-in-reflection-metadata/58852">Opt-in Reflection metadata</a></p></li><li><p><a href="https://forums.swift.org/t/pitch-a-new-kind-of-extension/59328">A New Kind Of Extension</a></p></li></ul><hr /><blockquote><p>✨ Want to see your ad here? Contact me at <a href="mailto:ads@fline.dev">ads@fline.dev</a> to get in touch.</p></blockquote><hr /><h2 id="other-developments-worth-mentioning">Other Developments worth Mentioning</h2><p>As the introductory comment was long, I’m keeping this section short:</p><ul><li><p>Some pitches seem to get <a href="https://forums.swift.org/t/pitch-attribute-to-silence-deprecation-warnings-for-a-specified-scope/57791/52">discussed and “guided”</a> proactively in a different direction by the new Language workgroup. To see how often this happened in the past I did a quick search for “The Language Workgroup / Core Team discussed this”, revealing only <a href="https://forums.swift.org/t/core-team-vs-random-number-api-discussion/7216">this</a> and <a href="https://forums.swift.org/t/swift4-priorities-and-sugar/3613/2">that</a> comment. I’ll keep an eye on it.</p></li><li><p>A Documentation Workgroup, which I reported <a href="https://www.fline.dev/swift-evolution-monthly-may-22/#other-developments-worth-mentioning">in the May issue</a> as currently being discussed, has now been <a href="https://forums.swift.org/t/announcing-the-documentation-workgroup/59144/1">officially announced</a>. The details are still in planning, but if you’re interested “use the <a href="https://forums.swift.org/new-message?groupname=swift-documentation-workgroup&ref=fline.dev">@swift-documentation-workgroup</a> handle to reach out to the workgroup directly in forums”.</p></li></ul><p>That’s it from the July update!<br />(Sent a bit later this time because I’m currently on vacation. 🌴)</p><blockquote><p>💁🏻‍♂️ <strong>Enjoyed this article? Check out my app RemafoX!</strong>
A native Mac app that integrates with Xcode to help translate <strong>your</strong> app.
<a href="https://apps.apple.com/app/apple-store/id1605635026?pt=549314&ct=fline.dev&mt=8&ref=fline.dev"><strong>Get it now</strong></a> to save time during development &amp; make localization easy.</p></blockquote>]]></content:encoded>
<media:thumbnail url="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-july-22/hero.webp"/>
</item>
<item>
<title>Swift Evolution Monthly: June ’22</title>
<link>https://evolutionkit.dev/blog/swift-evolution-monthly-june-22/</link>
<guid isPermaLink="true">https://evolutionkit.dev/blog/swift-evolution-monthly-june-22/</guid>
<pubDate>Sun, 26 Jun 2022 00:00:00 +0000</pubDate>
<description><![CDATA[WWDC22, new `@const` attribute, improved `some`, convenient Generic extensions, and Swift 6 feature flags for early adopters.]]></description>
<content:encoded><![CDATA[<p><img src="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-june-22/hero.webp" alt="Swift Evolution Monthly: June ’22" /></p><p>WWDC22 brought so many new APIs that despite me <a href="https://www.youtube.com/playlist?list=PLvkAveYAfY4SNTrJb_WugjkbBzg_YjyP4&ref=fline.dev">watching</a> and <a href="https://twitter.com/jeehut/status/1536077070958317568">summarizing</a> over 20 sessions in just the first week, I still haven’t watched all sessions <a href="https://www.youtube.com/watch?v=v6Wg7cAN1A8&list=PLvkAveYAfY4S9DXdzZpMbhF2GUkiQ1jjm&index=5&ref=fline.dev">I marked as favorite</a> yet and am still watching 5–10 sessions a week. But I’m almost done now and my overall impression is that this year we got a lot of developer ergonomics improvements both in SwiftUI &amp; Xcode and even the biggest star of the conference — the new <a href="https://developer.apple.com/videos/play/wwdc2022/10136/">Charts</a> framework — adds to that.</p><p>Apple engineers also did a great job of introducing some of the new Swift features that are shipping with Swift 5.7, some of which we have covered in past issues of this newsletter. Here are some you might be interested in:</p><ul><li><p><strong>Plugins</strong>: <a href="https://developer.apple.com/videos/play/wwdc2022/110359">Meet Swift Package plugins</a> &amp; <a href="https://developer.apple.com/videos/play/wwdc2022/110401">Create Swift Package plugins</a></p></li><li><p><strong>Generics</strong>: <a href="https://developer.apple.com/videos/play/wwdc2022/110352">Embrace Swift generics</a> &amp; <a href="https://developer.apple.com/videos/play/wwdc2022/110353">Design protocol interfaces in Swift</a></p></li><li><p><strong>Concurrency</strong>: <a href="https://developer.apple.com/videos/play/wwdc2022/110351">Eliminate data races using</a> / <a href="https://developer.apple.com/videos/play/wwdc2022/110350">Visualize and optimize</a> Swift</p></li><li><p><strong>Actors</strong>: <a href="https://developer.apple.com/videos/play/wwdc2022/110356">Meet distributed actors in Swift</a> (+ last year’s talk on <a href="https://developer.apple.com/videos/play/wwdc2021/10133">Swift actors</a>)</p></li><li><p><strong>Regex</strong>: <a href="https://developer.apple.com/videos/play/wwdc2022/110357">Meet Swift Regex</a> &amp; <a href="https://developer.apple.com/videos/play/wwdc2022/110358">Swift Regex: Beyond the basics</a></p></li></ul><p>But let’s get back to what’s new in Swift Evolution to learn about some proposals that are also all going to improve developer ergonomics!</p><h2 id="accepted-proposals">Accepted Proposals</h2><p>The following proposals already presented in the past have been <strong>accepted</strong>:</p><ul><li><p><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0352-implicit-open-existentials.md">SE-0352: Implicitly Opened Existentials</a> (<a href="https://forums.swift.org/t/accepted-se-0352-implicitly-opened-existentials/57553">Rationale</a> <strong>✅</strong>)</p></li><li><p><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0353-constrained-existential-types.md">SE-0353: Constrained Existential Types</a> (<a href="https://forums.swift.org/t/accepted-se-0353-constrained-existential-types/57560">Rationale</a> <strong>✅</strong>)</p></li><li><p><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0356-swift-snippets.md">SE-0356: Swift Snippets</a> (<a href="https://forums.swift.org/t/accepted-with-modifications-se-0356-swift-snippets/58150">Rationale + Modifications</a> <strong>✅</strong>)</p></li></ul><h2 id="proposals-in-reviewrevisionawaiting-decision">Proposals In Review/Revision/Awaiting Decision</h2><blockquote><p><strong>For the following proposals, you can still provide feedback. The current <a href="https://apple.github.io/swift-evolution/#?status=rejected">rejection</a> rate is less than 10%, so it’s likely they get accepted. <a href="https://github.com/apple/swift-evolution/blob/main/process.md#proposal-states">Revisions</a> are more common.</strong></p></blockquote><p>The following proposals already presented were <strong>returned for revision</strong>:</p><ul><li><p><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0354-regex-literals.md">SE-0354: Regex Literals</a> (<a href="https://forums.swift.org/t/returned-for-revision-se-0354-regex-literals/57366">Rationale</a> 🔄 | <a href="https://forums.swift.org/t/se-0354-regex-literals/57037">Review</a> <strong>🧵</strong>)</p></li><li><p><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0357-regex-string-processing-algorithms.md">SE-0357: Regex String Processing Algorithms</a> (<a href="https://forums.swift.org/t/se-0357-regex-string-processing-algorithms/57225/32">Rationale</a> 🔄 | <a href="https://forums.swift.org/t/se-0357-regex-string-processing-algorithms/57225">Review</a> <strong>🧵</strong>)</p></li></ul><p><strong>On to new proposals currently in review (or still awaiting a decision)!</strong></p><h3 id="se-0359-build-time-constant-values">SE-0359: Build-Time Constant Values</h3><p><strong>Links:</strong> <strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0359-build-time-constant-values.md"><strong>Proposal Document</strong></a></strong> 📝 | <strong><a href="https://forums.swift.org/t/se-0359-build-time-constant-values/57562"><strong>Review</strong></a></strong> 🧵**</p><p>Have you ever found it inconvenient that initializing a <code>URL</code> with a clearly valid String literal like <code>[https://apple.com](https://apple.com/)</code> returned an <code>Optional</code>? I did. I actually always force-unwrap them using by appending <code>!</code>. But <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0359-build-time-constant-values.md#enforcement-of-non-failable-initializers">no more</a>!</p><p>This proposal adds a <strong>new <strong><code>**@const**</code></strong> attribute</strong> to type properties, function parameters, and even protocols. This will allow restricting APIs to only accept values that are** known at compile-time** — so basically, we will only be able to pass literal values to them. Future proposals will then be able to add functionality into the toolchain that will allow us to add validity checks at build-time for APIs that are marked with <code>@const</code>, preventing us from shipping incorrect code. It also helps the Swift compiler further improve build time.</p><p>But that’s not all: This will allow for entirely <strong>new ways of using Swift</strong>, where merely building the code (but never executing it!) provides enough value, such as for the Swift package manifest file, which already has a <a href="https://forums.swift.org/t/pre-pitch-swiftpm-manifest-based-on-result-builders/53457">pre-pitch</a> to get the same treatment as Regexes have just gotten: A <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0359-build-time-constant-values.md#facilitate-compile-time-extraction-of-values">DSL-style syntax</a>!</p><p>Does that mean we will be able to write a DSL language that can be easily used as a replacement for config file formats like YAML? <a href="https://forums.swift.org/t/se-0359-build-time-constant-values/57562/75">Probably</a>. The example mentioned in the proposal is a “build-time extractable database schema”. This is how a new Swift persistence framework could work. 😍</p><h3 id="se-0360-opaque-result-types-with-limited-availability">SE-0360: Opaque result types with limited availability</h3><p><strong>Links:</strong> <strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0360-opaque-result-types-with-availability.md"><strong>Proposal Document</strong></a></strong> 📝 | <strong><a href="https://forums.swift.org/t/se-0360-opaque-result-types-with-limited-availability/57729"><strong>Review</strong></a></strong> 🧵**</p><p>This basically widens the applicability of <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0244-opaque-result-types.md">SE-0244: Opaque Result Types</a> to very simple <code>if #available</code> checks which is useful for framework authors. For example, the following example currently doesn’t compile because the <code>some Shape</code> opaque result type requires that the body returns exactly one specific type, but we have two different return types (Rectangle and Square):</p><p><img src="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-june-22/se-0360-opaque-result.webp" alt="" loading="lazy" /></p><p>With this proposal, the above code would compile. But don’t get too hyped, the following already doesn’t compile due to the dynamic if condition:</p><p><img src="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-june-22/se-0360-opaque-result-2.webp" alt="" loading="lazy" /></p><p>So in most cases, you will still need to resort back to existential <code>any</code> (<a href="https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md">SE-0335</a>) or <a href="https://www.swiftbysundell.com/articles/different-flavors-of-type-erasure-in-swift/">other means of type erasure</a> if you have multiple return types. By the way, I strongly recommend watching the WWDC22 session <a href="https://developer.apple.com/videos/play/wwdc2022/110352/">Embrace Swift generics</a> if you struggle with the new <code>some</code> and <code>any</code> keywords and when to use which. It starts with a quick introduction to protocol-oriented programming, goes into how you can replace <code>where T: Animal</code> with <code>some Animal</code>, and then explains the differences between <code>some</code> and <code>any</code> pretty well.</p><h3 id="se-0361-extensions-on-bound-generic-types">SE-0361: Extensions on bound generic types</h3><p><strong>Links:</strong> <strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0361-bound-generic-extensions.md"><strong>Proposal Document</strong></a></strong> 📝 | <strong><a href="https://forums.swift.org/t/se-0361-extensions-on-bound-generic-types/58366"><strong>Review</strong></a></strong> 🧵**</p><p>This is another proposal for making generics more ergonomic by allowing a more natural and expected syntax when using them. In this proposal, extensions are tackled. In short, all of the 3 following extensions statements on a generic type would in the future compile and have the same meaning:</p><p><img src="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-june-22/se-0361-extensions.webp" alt="" loading="lazy" /></p><p>Note that this will only work if all generic type arguments are provided, so if you have a type with multiple generic types and you just want to specify one in your extension, you’d have to resort back to the <code>where</code> clause.</p><p>As you can see in the above examples, even syntactical sugar variants will be supported, including optionals. So you’ll be able to write <code>extension String?</code>instead of <code>extension Optional where Wrapped == String</code>.</p><h3 id="se-0362-piecemeal-adoption-of-future-language-improvements">SE-0362: Piecemeal adoption of future language improvements</h3><p><strong>Links:</strong> <strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0362-piecemeal-future-features.md"><strong>Proposal Document</strong></a></strong> 📝 | <strong><a href="https://forums.swift.org/t/se-0362-piecemeal-adoption-of-future-language-improvements/58384"><strong>Review</strong></a></strong> 🧵**</p><p>Source-breaking changes in Swift are handled with great caution. So much so, that some new language features are already implemented and shipped with versions of Swift 4/5, but are disabled because they are marked as “only available in Swift 6 language mode”. Some of them shipped with a custom feature flag to turn them on today but even they are hard to explore.</p><p>This proposal streamlines that by adding the feature flag specifier <code>--enable-future-feature</code> and requiring all future &amp; even past proposals to adopt this by specifying their own feature identifier for it. This way developers have a unified way to enable and adopt select new features at their own pace.</p><p>This not only gives you the benefit of a Swift 6 improvement today but also allows you to easily prepare for Swift 6 on a step-by-step basis. I encourage you to turn on each feature one by one to see its impact to your code base as soon as the unified flags are available. This way you can discuss each feature with your team and create a roadmap for when to enable them to smoothen your transition to Swift 6 proactively.</p><p>Thanks to a new <code>#if hasFeature()</code> check, it will even be possible to keep two versions of the same code to not have to change your code when enabling/disabling a feature or simply to support the integration of your framework into tools where the feature is not available. For example:</p><p><img src="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-june-22/se-0362-piecemeal-2.webp" alt="" loading="lazy" /></p><p>The adoption of specific features will also be possible by specifying an array of feature identifiers to a <code>target</code> in SwiftPM manifest files like so:</p><p><img src="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-june-22/se-0362-piecemeal.webp" alt="" loading="lazy" /></p><p>Here’s a list of all initial feature identifiers that are planned to be supported:</p><ul><li><p><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0274-magic-file.md">SE-0274</a>: <code>ConciseMagicFile</code></p></li><li><p><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0286-forward-scan-trailing-closures.md">SE-0286</a>: <code>ForwardTrailingClosures</code></p></li><li><p><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md">SE-0335</a>: <code>ExistentialAny</code></p></li><li><p><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0337-support-incremental-migration-to-concurrency-checking.md">SE-0337</a>: <code>StrictConcurrency</code></p></li><li><p><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0352-implicit-open-existentials.md">SE-0352</a>: <code>ImplicitOpenExistentials</code> (covered in <a href="https://se-monthly.flinedev.com/issues/swift-evolution-monthly-april-22-regex-overhaul-improved-existentials-swift-5-7-timeline-1093738">April Issue</a>)</p></li><li><p><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0354-regex-literals.md">SE-0354</a>: <code>BareSlashRegexLiterals</code> (covered in <a href="https://se-monthly.flinedev.com/issues/swift-evolution-monthly-may-22-regex-overhaul-pt-ii-swift-snippets-new-workgroups-1146132">May Issue</a>)</p></li></ul><hr /><blockquote><p>✨ Want to see your ad here? Contact me at <a href="mailto:ads@fline.dev">ads@fline.dev</a> to get in touch.</p></blockquote><hr /><h2 id="recently-active-pitchesdiscussions">Recently Active Pitches/Discussions</h2><p>Some threads inside the “Evolution” category with activity within the last month I didn’t link yet. I’ll cover them in detail once they become proposals:</p><ul><li><p>**<code>is case</code>: pattern-match boolean expressions: **<a href="https://forums.swift.org/t/proposal-draft-for-is-case-pattern-match-boolean-expressions/58260">Discussion</a> 🧵</p></li><li><p><strong>In-Line Tests</strong>: <a href="https://forums.swift.org/t/rfc-in-line-tests/12111">Discussion</a> 🧵</p></li><li><p>**Introduce type-private access level: **<a href="https://forums.swift.org/t/introduce-type-private-access-level/58438">Discussion</a> 🧵</p></li><li><p><strong>Eliding <code>some</code> in Swift 6</strong>: <a href="https://forums.swift.org/t/discussion-eliding-some-in-swift-6/57918">Discussion</a> 🧵</p></li><li><p><strong>Move Function + “Use After Move” Diagnostic</strong>: <a href="https://github.com/jckarter/swift-evolution/blob/move-function/proposals/nnnn-move-function.md">Draft</a> **📝 | **<a href="https://forums.swift.org/t/pitch-move-function-use-after-move-diagnostic/53983">Discussion</a> 🧵</p></li><li><p><strong>SPM: Allow targets to depend on products in package</strong>: <a href="https://forums.swift.org/t/pitch-spm-allow-targets-to-depend-on-products-in-the-same-package/57717">Discuss</a> 🧵</p></li><li><p><strong>Conditional compilation for attributes and modifiers</strong>: <a href="https://forums.swift.org/t/pitch-conditional-compilation-for-attributes-and-modifiers/58339">Discuss</a> 🧵</p></li><li><p><strong>Expose property name to property wrapper</strong>: <a href="https://forums.swift.org/t/expose-property-name-to-property-wrapper/38660">Discuss</a> 🧵</p></li><li><p><strong>Use <code>some</code> as “some specialization of generic type”</strong>: <a href="https://forums.swift.org/t/pitch-use-some-to-express-some-specialization-of-a-generic-type/57913">Discuss</a> 🧵</p></li><li><p><strong><code>#if hasSymbol</code> compile time check for availability</strong>: <a href="https://forums.swift.org/t/discussion-if-hassymbol-module-symbol-a-compile-time-check-for-a-module-symbols-availability/58252">Discuss</a> 🧵</p></li><li><p>**Isolated synchronous deinit: **<a href="https://forums.swift.org/t/isolated-synchronous-deinit/58177">Discussion</a> 🧵</p></li></ul><blockquote><p>💁🏻‍♂️ <strong>Enjoyed this article? Check out my app <strong>RemafoX</strong>!</strong>
A native Mac app that integrates with Xcode to help translate <strong>your</strong> app.
<a href="https://apps.apple.com/app/apple-store/id1605635026?pt=549314&ct=fline.dev&mt=8&ref=fline.dev"><strong>Get it now</strong></a> to save time during development &amp; make localization easy.</p></blockquote>]]></content:encoded>
<media:thumbnail url="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-june-22/hero.webp"/>
</item>
<item>
<title>Swift Evolution Monthly: May ’22</title>
<link>https://evolutionkit.dev/blog/swift-evolution-monthly-may-22/</link>
<guid isPermaLink="true">https://evolutionkit.dev/blog/swift-evolution-monthly-may-22/</guid>
<pubDate>Fri, 20 May 2022 00:00:00 +0000</pubDate>
<description><![CDATA[Regex overhaul (pt. II), Swift Snippets, new Workgroups]]></description>
<content:encoded><![CDATA[<p><img src="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-may-22/hero.webp" alt="Swift Evolution Monthly: May ’22" /></p><p>Last month I presented the first two Regex (or String-processing) related proposals, stating that they are just “kicking off a series of Regex-related proposals”. And here we are, <strong>Regexes</strong> still being the main focus — and they will probably still be in next month’s issue.</p><p>But that doesn’t mean nothing else happened on Swift Evolution. There’s a very interesting proposal for adding <strong>Snippets</strong> support to SwiftPM. Also, multiple entirely new pitches were made by the community, some of which I’m linking below. And there’s also news on the <strong>organizational</strong> front.</p><p>Read on to learn more about all these developments!</p><h2 id="accepted-proposals">Accepted Proposals</h2><p>The following proposal already presented in the past has been <strong>accepted</strong>:</p><ul><li><p><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0350-regex-type-overview.md">SE-0350: Regex Type and Overview</a> (<a href="https://forums.swift.org/t/accepted-se-0350-regex-type-and-overview/57127">Rationale</a> <strong>✅</strong>)</p></li></ul><p><strong>No other proposals were accepted within the last month!</strong></p><h2 id="proposals-in-reviewrevision">Proposals In Review/Revision</h2><blockquote><p><strong>For the following proposals, you can still provide feedback. The current <a href="https://apple.github.io/swift-evolution/#?status=rejected">rejection</a> rate is less than 10%, so it’s likely they get accepted. <a href="https://github.com/apple/swift-evolution/blob/main/process.md#proposal-states">Revisions</a> are more common.</strong></p></blockquote><p>The following proposals already presented were <strong>returned for revision</strong>:</p><ul><li><p><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0351-regex-builder.md">SE-0351: Regex builder DSL</a> (<a href="https://forums.swift.org/t/returned-for-revision-se-0351-regex-builder-dsl/57224">Rationale 🔄</a>)</p></li><li><p><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0352-implicit-open-existentials.md">SE-0352: Implicitly Opened Existentials</a> (<a href="https://forums.swift.org/t/se-0352-second-review-implicitly-opened-existentials/56878">Review <strong>🧵</strong></a>)</p></li><li><p><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0353-constrained-existential-types.md">SE-0353: Constrained Existential Types</a> (<a href="https://forums.swift.org/t/se-0353-constrained-existential-types/56853">Review <strong>🧵</strong></a>)</p></li></ul><p><strong>On to new proposals in review!</strong></p><h3 id="se-0354-regex-literals">SE-0354: Regex Literals</h3><p><strong>Links:</strong> <strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0354-regex-literals.md"><strong>Proposal Document</strong></a></strong> 📝 | <strong><a href="https://forums.swift.org/t/se-0354-second-review-regex-literals/57367"><strong>Review</strong></a></strong> 🧵**</p><p>Regex literals will provide a safer way to define regular expressions than passing a pattern <code>String</code>: While a pattern <code>String</code> can only be checked for syntax errors (such as an opening brace <code>(</code> without a closing brace <code>)</code>) during runtime (= when the code is executed by the user), the literal can be checked at compile-time (= when you build your app) and therefore it will help reduce crashes for your users or error handling code for you because you don’t have to catch any errors. The syntax will look familiar to those experienced in languages like Ruby, Perl, or JavaScript:</p><p><img src="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-may-22/comparison-of-different.webp" alt="" loading="lazy" /></p><p>Then, in your documentation comments, instead of placing sample code via three backticks, you’ll be able to just use the new DocC directive <code>@Snippet</code>:</p><p><img src="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-may-22/the-highlighted-code-is-3.webp" alt="" loading="lazy" /></p><p>This will place the **presentation code **of your snippet file right into the documentation view within Xcode or add it to your HTML file. What is the <strong>presentation code</strong>, you ask? Well, because all snippet files will be Swift files that we will be able to compile via <code>swift build --build-snippets</code> (and library authors should make sure to run that on their CI), you might need to write some helper code that is just churn and might not be relevant to showing off your functionality. The proposal gives us a way to hide some parts of our code, for that we simply add <code>// MARK: HIDE</code> and <code>// MARK: SHOW</code>:</p><p><img src="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-may-22/the-highlighted-code-is.webp" alt="" loading="lazy" /></p><p>We will also get a <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0357-regex-string-processing-algorithms.md#ranges">new </a><code>[ranges](https://github.com/apple/swift-evolution/blob/main/proposals/0357-regex-string-processing-algorithms.md#ranges)</code><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0357-regex-string-processing-algorithms.md#ranges"> function</a> saving us from writing a loop or reduce function just to get multiple matching ranges, see this example:</p><p><img src="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-may-22/se-0357-regex-powered.webp" alt="" loading="lazy" /></p><p>And there are still many APIs we only have access to through <code>NSString</code> (and therefore Objective-C), like <code>[replacingOccurrences(of:with:)](https://developer.apple.com/documentation/foundation/nsstring/1412937-replacingoccurrences)</code> which will now get a <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0357-regex-string-processing-algorithms.md#replace">new </a><code>[replacing(_:with:)](https://github.com/apple/swift-evolution/blob/main/proposals/0357-regex-string-processing-algorithms.md#replace)</code><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0357-regex-string-processing-algorithms.md#replace"> Swift-native API</a>.</p><p>See <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0357-regex-string-processing-algorithms.md#string-algorithm-additions">this table</a> for a summarizing list of all new APIs getting added to Swift.</p><p>On top of these new APIs, the proposal is also adding a <code>~=</code> operator overload for pattern matching with Regexes + a <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0357-regex-string-processing-algorithms.md#customconsumingregexcomponent">new </a><code>[CustomConsumingRegexComponent](https://github.com/apple/swift-evolution/blob/main/proposals/0357-regex-string-processing-algorithms.md#customconsumingregexcomponent)</code><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0357-regex-string-processing-algorithms.md#customconsumingregexcomponent"> protocol</a>which will allow Apple &amp; 3rd party library authors to make their own types directly usable in many of the new APIs + within the <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0351-regex-builder.md">Regex builder DSL</a>.</p><h3 id="se-0358-primary-associated-types-in-the-standard-library">SE-0358: Primary Associated Types in the Standard Library</h3><p><strong>Links:</strong> <strong><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0358-primary-associated-types-in-stdlib.md"><strong>Proposal Document</strong></a></strong> 📝 | <strong><a href="https://forums.swift.org/t/se-0358-primary-associated-types-in-the-standard-library/57432"><strong>Review</strong></a></strong> 🧵**</p><p>This one is a follow-up proposal to <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0346-light-weight-same-type-syntax.md">SE-0346</a> (presented in <a href="https://se-monthly.flinedev.com/issues/swift-evolution-monthly-first-issue-background-history-chris-lattner-6-proposals-1092625">first issue</a>) and basically is about extending the Standard Library with the new primary associated type declarations in order to make SE-0346 actually usable.</p><p>See <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0358-primary-associated-types-in-stdlib.md#proposed-solution">this table</a> for an overview of all the protocols planned to be changed.</p><h2 id="recently-active-pitchesdiscussions">Recently Active Pitches/Discussions</h2><p>Some threads inside the “Evolution” category with activity within the last month I didn’t link yet. I’ll cover them once they become official proposals:</p><ul><li><p><strong>Piecemeal adoption of Swift 6 features in Swift 5.x</strong>: <a href="https://forums.swift.org/t/piecemeal-adoption-of-swift-6-improvements-in-swift-5-x/57184">Discussion</a> 🧵</p></li><li><p><strong>Keypath-based sort/min/max Sequence operations</strong>: <a href="https://forums.swift.org/t/pitch-keypath-based-sort-min-max-sequence-operations/57153">Discussion</a> 🧵</p></li><li><p><strong>Allow non-optional getters for optional requirements</strong>: <a href="https://forums.swift.org/t/allow-non-optional-getters-as-protocol-witnesses-for-optional-requirements/57160">Discussion</a> 🧵</p></li><li><p><strong>Unicode for String Processing</strong>: <a href="https://github.com/natecook1000/swift-evolution/blob/unicode_string_processing/proposals/0000-unicode-for-string-processing.md">Draft</a> **📝 | **<a href="https://forums.swift.org/t/pitch-unicode-for-string-processing/56907">Discussion</a> 🧵</p></li><li><p><strong>Will string processing efforts also expose Bidi_Class?</strong>: <a href="https://forums.swift.org/t/will-the-string-processing-efforts-also-expose-bidi-class/56898">Discussion</a> 🧵</p></li><li><p><strong>Approximate equality for floating-point</strong>: <a href="https://forums.swift.org/t/approximate-equality-for-floating-point/22420">Discussion</a> 🧵</p></li><li><p><strong>Opaque result types with limited availability</strong>: <a href="https://forums.swift.org/t/pitch-opaque-result-types-with-limited-availability/57286">Discussion</a> 🧵</p></li><li><p><strong>Standardise <strong><code>**swift test**</code></strong> across platforms</strong>: <a href="https://forums.swift.org/t/standardise-swift-test-across-platforms/56733">Discussion</a> 🧵</p></li><li><p><strong>Improving <strong><code>**String.Index**</code></strong>’s printed descriptions</strong>: <a href="https://forums.swift.org/t/improving-string-index-s-printed-descriptions/57027">Discussion</a> 🧵</p></li><li><p>**Have all adapters in the std lib expose their **<code>**base**</code>: <a href="https://forums.swift.org/t/pitch-have-all-adapters-in-the-standard-library-uniformly-expose-their-base/56830">Discussion</a> 🧵</p></li></ul><h2 id="other-developments-worth-mentioning">Other Developments worth Mentioning</h2><p>The <a href="https://forums.swift.org/t/swift-bugs-are-moving-to-github-issues-and-we-need-your-help/56125">migration</a> of Swift bug reports to GitHub has been <a href="https://forums.swift.org/t/swift-bugs-have-migrated-to-github-issues/56960">completed</a> with more than 12,000 issues of which more than 5,000 are marked as “Open”: See <a href="https://github.com/apple/swift/issues">here</a>.</p><p><a href="https://twitter.com/tkremenek">Ted Kremenek</a>, officially <a href="https://www.swift.org/community/#project-lead">representing Apple</a> in the Swift community and Core Team member, <a href="https://forums.swift.org/t/core-team-to-form-language-workgroup/55455/37">posted an update</a> to the same thread where <a href="https://twitter.com/clattner_llvm">Chris Lattner</a>, the originator of Swift, had posted his reasons to depart from the Swift community (which I had already discussed at the end of the <a href="https://se-monthly.flinedev.com/issues/swift-evolution-monthly-first-issue-background-history-chris-lattner-6-proposals-1092625#other-developments-worth-mentioning">first issue</a>). This shows that their efforts to split the Core team’s responsibilities for improving upon some of the criticized aspects are making progress.</p><p>More specifically, he mentions a new language design work group and that “the goal is to make the core team more of a general oversight group”. He specifically mentioned that a documentation tooling workgroup is being discussed, an also mentioned <a href="https://forums.swift.org/t/swift-website-work-group/57273">Swift website workgroup was already formed</a> with none other than <a href="https://twitter.com/twostraws">Paul Hudson</a> and <a href="https://twitter.com/daveverwer">Dave Verwer</a> as members, among others.</p><p>On the same note, a <a href="https://forums.swift.org/t/formalizing-a-numerical-ml-working-group/45553">Numerical/ML workgroup</a> is being discussed, too. And speaking about workgroups, the Swift Server Workgroup has just posted its <a href="https://forums.swift.org/t/swift-server-workgroup-2021-annual-update/56977">annual update</a>.</p><p>That’s it from <strong>my</strong> monthly update!</p><blockquote><p>💁🏻‍♂️ <strong>Enjoyed this article? Check out my app <strong>RemafoX</strong>!</strong>
A native Mac app that integrates with Xcode to help translate <strong>your</strong> app.
<a href="https://apps.apple.com/app/apple-store/id1605635026?pt=549314&ct=fline.dev&mt=8&ref=fline.dev"><strong>Get it now</strong></a> to save time during development &amp; make localization easy.</p></blockquote>]]></content:encoded>
<media:thumbnail url="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-may-22/hero.webp"/>
</item>
<item>
<title>Swift Evolution Monthly: April ‘22</title>
<link>https://evolutionkit.dev/blog/swift-evolution-monthly-april-22/</link>
<guid isPermaLink="true">https://evolutionkit.dev/blog/swift-evolution-monthly-april-22/</guid>
<pubDate>Thu, 21 Apr 2022 00:00:00 +0000</pubDate>
<description><![CDATA[Regex overhaul, improved Existentials, Swift 5.7 timeline]]></description>
<content:encoded><![CDATA[<p><img src="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-april-22/hero.webp" alt="Swift Evolution Monthly: April ‘22" /></p><p>Wow, this is just the 2nd issue of <a href="https://se-monthly.flinedev.com/">this newsletter</a> and nearly 300 developers subscribed to it, already! All thanks to <a href="https://iosdevweekly.com/issues/551#news">Dave</a> and others <a href="https://twitter.com/mtjc_podcast/status/1507455830903468035?s=20&t=N5p28GqtRUn43vcHZOq3Lw&ref=fline.dev">from</a> <a href="https://twitter.com/hasdid/status/1508138533097254918?s=20&t=N5p28GqtRUn43vcHZOq3Lw&ref=fline.dev">the</a> <a href="https://twitter.com/iosdevtools/status/1511273437335019525?s=21&t=njLNDTb7cCMjruD1Y3CrWg&ref=fline.dev">community</a> for spreading the word. Thank you! 🙏</p><p>I heard your feedback: You’re right, the first issue was too long. Partly because it was never planned to be released as a newsletter, and partly because it was the first, so I gave a (lengthy) introduction. Despite covering more proposals today, this issue is only ~60% of the length! (2,400 words → 1,500 words)</p><p>The two main focus topics on Swift Evolution this past month both sound a bit scary: <strong>Regular Expressions</strong> and <strong>Existentials</strong>. But don’t worry: The Regex story can be broken down to “Swift is making them less scary!”. And I didn’t know what an “Existential” was before writing this issue myself — I’ll explain!</p><p>Enjoy. 🍻</p><h2 id="accepted-proposals">Accepted Proposals</h2><p>The following proposals presented in past issues have been <strong>accepted</strong>:</p><ul><li><p><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0344-distributed-actor-runtime.md">SE-0344: Distributed Actor Runtime</a> (<a href="https://forums.swift.org/t/accepted-se-0344-distributed-actor-runtime/56416">Rationale</a> ✅)</p></li><li><p><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0345-if-let-shorthand.md">SE-0345: </a><code>[if let](https://github.com/apple/swift-evolution/blob/main/proposals/0345-if-let-shorthand.md)</code><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0345-if-let-shorthand.md"> shorthand for shadowing an existing optional variable</a>(<a href="https://forums.swift.org/t/accepted-se-0345-if-let-shorthand-for-shadowing-an-existing-optional-variable/56364">Rationale</a> ✅)</p></li><li><p><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0346-light-weight-same-type-syntax.md">SE-0346: Lightweight same-type requirements for primary associated types</a>(<a href="https://forums.swift.org/t/accepted-se-0346-lightweight-same-type-requirements-for-primary-associated-types/56747">Rationale</a> ✅)</p></li></ul><p>Also, one more proposal was <strong>accepted</strong> that I had not mentioned because I found it not relevant to app developers. From now on I’ll mention these kinds of proposals, too, with a short comment on who this might be of interest to. This one mostly concerns those shipping Swift packages to Linux systems:</p><ul><li><p><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0342-static-link-runtime-libraries-by-default-on-supported-platforms.md">SE-0342: Statically link Swift runtime libraries by default on supported platforms</a> (<a href="https://forums.swift.org/t/accepted-se-0342-statically-link-swift-runtime-libraries-by-default-on-supported-platforms/56517">Rationale</a> ✅)</p></li></ul><p>On to new proposals!</p><h3 id="se-0347-type-inference-from-default-expressions">SE-0347: Type inference from default expressions</h3><p><strong>Links:</strong> <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0347-type-inference-from-default-exprs.md">Proposal Document</a> 📝 | <a href="https://forums.swift.org/t/accepted-se-0347-type-inference-from-default-expressions/56558">Acceptance Rationale</a> ✅ | <a href="https://forums.swift.org/t/se-0347-type-inference-from-default-expressions/56142">Review</a> 🧵</p><p>Currently, providing a default value for generic parameters produces an error:</p><p><img src="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-april-22/note-that-the-first-2.webp" alt="" loading="lazy" /></p><p>Starting with (<a href="https://github.com/apple/swift/pull/41436">probably</a>) Swift <code>5.7</code>, the above code will compile <strong>success</strong>fully! Here’s another example of what will be possible with the usage side included:</p><p><img src="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-april-22/note-that-the-first.webp" alt="" loading="lazy" /></p><h3 id="se-0348-buildpartialblock-for-result-builders">SE-0348: buildPartialBlock for result builders</h3><p><strong>Links:</strong> <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0348-buildpartialblock.md">Proposal Document</a> 📝 | <a href="https://forums.swift.org/t/pitch-buildpartialblock-for-result-builders/55561">Review</a> 🧵</p><p>This one will only concern you <strong>directly</strong> if you try <a href="https://developer.apple.com/videos/play/wwdc2021/10253/">writing a DSL using Result Builders</a>. But even as a user of frameworks like SwiftUI or Point-Free’s <a href="https://github.com/pointfreeco/swift-parsing">swift-parsing</a>, you are going to benefit from this <strong>indirectly</strong> because it <strong>significantly reduces the number of overloads</strong> the library authors have to write to make things like <code>VStack</code> support multiple subviews.</p><p>This should allow Apple to accept <strong>more than 10 views</strong> in the future, making <a href="https://stackoverflow.com/a/58398355">workarounds like </a><code>[Group](https://stackoverflow.com/a/58398355)</code> less necessary. Point-Free has <a href="https://forums.swift.org/t/pitch-buildpartialblock-for-result-builders/55561/10">already reported</a> that they will be able to increase their parser builder limit from 6 to above 10 and even to infinity for some specific combination of types. Cross-platform SwiftUI implementations such as <a href="https://github.com/TokamakUI/Tokamak">Tokamak</a> or <a href="https://github.com/stackotter/swift-cross-ui">Swift Cross UI</a> should profit from this, too. It’s also going to allow for new types of builders, such as the new <code>[RegexComponentBuilder](https://github.com/apple/swift-experimental-string-processing/blob/85c7d906dd871364357156126278d9d427936ca4/Sources/_StringProcessing/RegexDSL/Builder.swift#L13)</code> planned for the Regex proposals below.</p><p>The feature is already implemented and will ship with Swift <code>5.7</code>.</p><h3 id="se-0349-unaligned-loads-and-stores-from-raw-memory">SE-0349: Unaligned Loads and Stores from Raw Memory</h3><p><strong>Links:</strong> <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0349-unaligned-loads-and-stores.md">Proposal Document</a> 📝 | <a href="https://forums.swift.org/t/accepted-se-0349-unaligned-loads-and-stores-from-raw-memory/56748">Acceptance Rationale</a> ✅ | <a href="https://forums.swift.org/t/se-0349-unaligned-loads-and-stores-from-raw-memory/56423">Review</a> 🧵</p><p>Helps prevent alignment mismatches in <strong>low-level</strong> byte data parsing by introducing a new <code>loadUnaligned</code> function. <a href="https://github.com/apple/swift/pull/41033">Probably</a> ships with Swift <code>5.7</code>.</p><h2 id="proposals-in-reviewrevision">Proposals In Review/Revision</h2><blockquote><p><strong>For the following proposals, you can still provide feedback. The current <a href="https://apple.github.io/swift-evolution/#?status=rejected">rejection</a> rate is less than 10%, so it’s likely they get accepted. <a href="https://github.com/apple/swift-evolution/blob/main/process.md#proposal-states">Revisions</a> are more common.</strong></p></blockquote><h3 id="se-0350-regex-type-and-overview">SE-0350: Regex Type and Overview</h3><p><strong>Links:</strong> <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0350-regex-type-overview.md">Proposal Document</a> 📝 | <a href="https://forums.swift.org/t/se-0350-regex-type-and-overview/56530">Review</a> 🧵</p><p>This is a big one. Not necessarily this proposal specifically. But it is kicking off a <a href="https://github.com/apple/swift-experimental-string-processing/blob/main/Documentation/Evolution/ProposalOverview.md">series of Regex-related proposals</a> that are going to greatly improve how we can process Strings to read/transform specific data from parts of them. To put things in context, this is the start to implement <a href="https://github.com/apple/swift-experimental-string-processing/blob/main/Documentation/DeclarativeStringProcessing.md">Declarative String Processing</a> in Swift, which itself is part of a larger <a href="https://github.com/apple/swift-experimental-string-processing/blob/main/Documentation/BigPicture.md">data processing improvement</a> plan.</p><p>But let’s get back to this proposal in particular. It introduces a <code>Regex</code> type:</p><p><img src="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-april-22/note-that-the-first-3.webp" alt="" loading="lazy" /></p><p>Furthermore, a <code>ChoiceOf</code> builder would allow specifying multiple variants (replaces <code>A|B</code>) and even a <code>TryCapture {} transform: {}</code> would be available to directly transform a sub-match into an expected type, such as into an <code>enum</code>. <code>Optionally</code> (for <code>A?</code>) and <code>Repeat</code> (for <code>A{n,m}</code>) complete the DSL:</p><p><img src="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-april-22/note-that-the-output-2.webp" alt="" loading="lazy" /></p><p>The <code>value</code> variable is of type “any type that conforms to <code>Codable</code>”. First, we use a <code>[String]</code>, then a plain <code>String</code> and it compiles successfully. Under the hoods, Swift 5 creates an existential box type for us implicitly and dynamically changes the type of the value stored inside it from <code>[String]</code> to <code>String</code>.</p><p>Since Swift <code>5.6</code> (thanks to <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md">SE-0335</a>) we can (and should!) make this existential more explicit by adding the keyword <code>any</code> in front of <code>Codable</code>:</p><p><img src="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-april-22/se-0352-implicitly.webp" alt="" loading="lazy" /></p><p>Starting with Swift 6, the first example will no longer compile and we will need to add <code>any</code> whenever we’re creating an existential type, to make its creation more explicit to developers. This is important because existential types are quite limited in Swift. Some of these limitations come from their <a href="https://www.swiftbysundell.com/articles/different-flavors-of-type-erasure-in-swift/?utm_campaign=Swift%20Evolution%20Monthly&utm_medium=email&utm_source=Revue%20newsletter">type-erasing</a> nature and can’t be fixed, but some <strong>can</strong> be fixed.</p><p>Developers would run into a whole set of compilation errors and had to work around them. But we are going to see improvements in the near future, like with <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0309-unlock-existential-types-for-all-protocols.md?utm_campaign=Swift%20Evolution%20Monthly&utm_medium=email&utm_source=Revue%20newsletter">SE-309</a> shipping with Swift <code>5.7</code>.</p><p>This proposal further improves working with existentials by smoothing out the interaction between them and generics. Calls to generic functions that would have failed with an error like “protocol ‘P’ as a type cannot conform to itself”, will now succeed. Additionally, before this, we could replace a <code>some View</code> parameter with <code>any View</code>, but not the other way around. This proposal would allow us to refactor in the other direction as well.</p><hr /><blockquote><p>✨ Want to see your ad here? Contact me at <a href="mailto:ads@fline.dev">ads@fline.dev</a> to get in touch.</p></blockquote><hr /><h3 id="se-0353-constrained-existential-types">SE-0353: Constrained Existential Types</h3><p><strong>Links:</strong> <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0353-constrained-existential-types.md">Proposal Document</a> 📝 | <a href="https://forums.swift.org/t/se-0353-constrained-existential-types/56853">Review</a> 🧵</p><p>In the <a href="https://jeehut.medium.com/swift-evolution-monthly-first-issue-7d276705c4e0?sk=ad1693bf56e189748f478e3538844aef&ref=fline.dev">previous issue</a>, we discussed <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0346-light-weight-same-type-syntax.md">SE-0346</a> which allows us to specify generic types in place instead of specifying them with a <code>where</code> clause at the end. This proposal aims to bring the same convenience to existential types with the <code>any</code>keyword:</p><p><img src="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-april-22/constrained-existentials.webp" alt="" loading="lazy" /></p><h2 id="recently-active-pitchesdiscussions">Recently Active Pitches/Discussions</h2><p>Here are some pitches/discussions with a recent activity you might find interesting — some of them are a continuation of topics discussed above. Of course, I will cover them in more detail once they become official proposals:</p><ul><li><p><strong>Regex Literals</strong>: <a href="https://forums.swift.org/t/pitch-2-regex-literals/56736">Discussion</a> 🧵</p></li><li><p><strong>Regex-powered string processing algorithms</strong>: <a href="https://forums.swift.org/t/pitch-regex-powered-string-processing-algorithms/55969">Discussion</a> 🧵</p></li><li><p><strong>Regex Syntax and Run-time Construction</strong>: <a href="https://github.com/apple/swift-experimental-string-processing/blob/main/Documentation/Evolution/RegexSyntaxRunTimeConstruction.md">Draft</a> 📝 | <a href="https://forums.swift.org/t/pitch-2-regex-syntax-and-run-time-construction/56624">Discussion</a> 🧵</p></li><li><p><strong>Precise error typing in Swift</strong>: <a href="https://forums.swift.org/t/precise-error-typing-in-swift/52045">Discussion</a> 🧵</p></li><li><p><strong>SwiftPM support for Swift scripts (revision)</strong>: <a href="https://forums.swift.org/t/pitch-swiftpm-support-for-swift-scripts-revision/46717">Discussion</a> 🧵</p></li><li><p><strong>Swift Snippets</strong>: <a href="https://github.com/bitjammer/swift-evolution/blob/acgarland/snippets/proposals/0353-snippets.md">Draft</a> 📝 | <a href="https://forums.swift.org/t/pitch-swift-snippets/56348">Discussion</a> 🧵</p></li><li><p><strong>Inclusion of CasePaths into the language</strong>: <a href="https://forums.swift.org/t/discussion-inclusion-of-casepaths-into-the-language/53024">Discussion</a> 🧵</p></li><li><p><strong>Global actors</strong>: <a href="https://github.com/DougGregor/swift-evolution/blob/global-actors/proposals/nnnn-global-actors.md">Draft</a> 📝 | <a href="https://forums.swift.org/t/pitch-global-actors/45706">Discussion</a> 🧵</p></li><li><p><strong>for-where-as</strong>: <a href="https://forums.swift.org/t/pitch-for-where-as/56419">Discussion</a> 🧵</p></li><li><p><strong>Primary Associated Types in the Standard Lib</strong>: <a href="https://github.com/lorentey/swift-evolution/blob/stdlib-pats/proposals/nnnn-primary-associated-types-in-stdlib.md">Draft</a> 📝 | <a href="https://forums.swift.org/t/pitch-primary-associated-types-in-the-standard-library/56426">Discussion</a> 🧵</p></li><li><p><strong>Full name identifiers:</strong> <a href="https://forums.swift.org/t/pitch-full-name-identifiers/56072">Discussion</a> 🧵</p></li><li><p><strong>Build-Time Constant Values</strong>: <a href="https://forums.swift.org/t/pitch-2-build-time-constant-values/56762">Discussion</a> 🧵</p></li></ul><h2 id="other-developments-worth-mentioning">Other Developments worth Mentioning</h2><p>Apple <a href="https://forums.swift.org/t/swift-5-7-release-process/56316">officially announced</a> the release process for Swift 5.7 on March 29th. Doing the math based on <a href="https://github.com/apple/swift-evolution#goals-and-release-notes">this table</a> in the Swift GitHub repo, a Swift release happens 5–6 months after its announcement on average. So it’s pretty safe to say we’ll be getting Swift 5.7 as part of the Xcode 14 release this autumn, starting with a first beta right after the <a href="https://developer.apple.com/wwdc22/">WWDC22 keynote</a> on June 6th.</p><p>In <a href="https://forums.swift.org/t/swift-bugs-are-moving-to-github-issues-and-we-need-your-help/56125">another announcement</a> from March 22nd, Apple laid out a timeline for migrating Swift bug reports over to GitHub from a <a href="https://bugs.swift.org/">separate JIRA system</a> that was in use until now. This should help with linking bugs to PRs properly as both the code and the related issues can live in one place. Also reporting bugs should become easier as you can just use your existing GitHub account. At the moment of this writing, the migration is ongoing and we can see <a href="https://github.com/swift-issues-migration/swift-issues-v2/issues">a read-only preview</a> of the migrated issues. The migration is planned to be completed by April 28th, then you should see the Issues tab in the <a href="https://github.com/apple/swift/issues">Swift repo</a>.</p><p>That’s it from this month’s update!</p><blockquote><p>💁🏻‍♂️ <strong>Enjoyed this article? Check out my app <strong>RemafoX</strong>!</strong>
A native Mac app that integrates with Xcode to help translate <strong>your</strong> app.
<a href="https://apps.apple.com/app/apple-store/id1605635026?pt=549314&ct=fline.dev&mt=8&ref=fline.dev"><strong>Get it now</strong></a> to save time during development &amp; make localization easy.</p></blockquote>]]></content:encoded>
<media:thumbnail url="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-april-22/hero.webp"/>
</item>
<item>
<title>Swift Evolution Monthly: First Issue</title>
<link>https://evolutionkit.dev/blog/swift-evolution-monthly-first-issue/</link>
<guid isPermaLink="true">https://evolutionkit.dev/blog/swift-evolution-monthly-first-issue/</guid>
<pubDate>Thu, 17 Mar 2022 00:00:00 +0000</pubDate>
<description><![CDATA[Summary of interesting developments on Swift Evolution - Update from 03/2022 + some background history (1st issue!)]]></description>
<content:encoded><![CDATA[<p><img src="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-first-issue/hero.webp" alt="Swift Evolution Monthly: First Issue" /></p><h3 id="recap-of-swift-evolution-history">Recap of Swift Evolution History</h3><p>Since the day <a href="https://developer.apple.com/swift/blog/?id=34&ref=fline.dev">Apple open-sourced Swift</a> in December 2015 it was possible to follow and even participate in the future of Swift. At the beginning the discussions were hard to explore &amp; a mess to follow due to their <a href="http://www.list.org/">mailing list</a> nature. Thankfully, more than a year <a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151207/001537.html">after the first suggestion</a> to migrate over to <a href="https://www.discourse.org/">a proper forum software</a> and dozens of participators <a href="https://forums.swift.org/t/swift4-mailing-list-vs-forum/3614">backing the idea</a>, the <a href="https://forums.swift.org/t/plan-to-move-swift-evolution-and-swift-users-mailing-lists-to-discourse/5128">Core Team had decided</a> to do the migration. It took nearly another year until the <a href="https://www.swift.org/blog/forums/">Swift Forums officially opened</a> in January 2018.</p><p>In the 4 years since then <strong>~17k developers</strong> discussed Swift topics in <strong>~27k threads</strong> with <strong>~245k posts</strong> overall as of March 2022 (<a href="https://forums.swift.org/about">source</a>). Even more developers (probably <a href="https://forums.swift.org/top?order=views&period=all&ref=fline.dev"><strong>~100k</strong></a>) have at least viewed and read some portion of them. A whole 9 new Swift versions were released since migrating to the forum, each accompanied by an official announcement blog article which lists all Swift Evolution proposals that went through the <a href="https://github.com/apple/swift-evolution/blob/main/process.md">Swift Evolution Process</a> and informed the changes: <a href="https://www.swift.org/blog/swift-4.1-released/">4.1</a>, <a href="https://www.swift.org/blog/swift-4.2-released/">4.2</a>, <a href="https://www.swift.org/blog/swift-5-released/">5.0</a>, <a href="https://www.swift.org/blog/swift-5.1-released/">5.1</a>, <a href="https://www.swift.org/blog/swift-5.2-released/">5.2</a>, <a href="https://www.swift.org/blog/swift-5.3-released/">5.3</a>, <a href="https://www.swift.org/blog/swift-5.4-released/">5.4</a>, <a href="https://www.swift.org/blog/swift-5.5-released/">5.5</a>, <a href="https://www.swift.org/blog/swift-5.6-released/">5.6</a>.</p><p><a href="https://forums.swift.org/t/on-the-road-to-swift-6/32862">The road to Swift 6</a> is outlined since January 2020 and is the most-viewed thread in the forum for a reason. It summarizes the Swift 6 focus in 3 areas:</p><p>First, <strong>“the Swift software ecosystem”</strong> to broaden Swifts usefulness outside of Apple app development. Second, <strong>“a fantastic development experience”</strong> like faster builds &amp; more accurate error messages. And third, <strong>“user-empowering language directions”</strong> such as improvements to concurrency, generics, DSLs, memory-ownership and low-level programming. All these areas have seen large steps forward since the announcement with the changes in Swift 5.2 and later, <a href="https://forums.swift.org/t/swift-concurrency-roadmap/41611">Swift Concurrency</a> being a large recent focus. But there’s still much work to be done in all of them, so Swift 6 release is not a topic for this year and we can expect at least Swift 5.7 and 5.8 before that.</p><h3 id="why-a-swift-evolution-monthly">Why a “Swift Evolution Monthly”?</h3><p>My main takeaway from the recap of the Swift Evolution history above is that <strong>the future development of Swift is truly a community effort</strong>. While Apple is still the main driver of this language (more on that at the end), setting the rough direction and current focus, we all have a say in all the details and can even make suggestions for improvements or entirely new features ourselves.</p><p>At the same time, we developers are “users” of the Swift language first and foremost. Being a “designer” of a language is an entirely different thing and can eat quite a large chunk of our precious time. Nevertheless, I’m personally very interested in what’s coming next in Swift so I can make informed decisions about which APIs or frameworks I make use of right now. And on which parts I maybe use a temporary solution and wait a couple of months before diving into making things proper. Because there might be a related Swift feature coming soon that will simplify things or allows entirely new concepts. But how would I know if I didn’t follow the discussions? And will the change actually work for my problem, too, or should I give feedback?</p><p>For these reasons, I sometimes wander around in the <a href="https://forums.swift.org/c/evolution/pitches/5">Pitches category</a> to find ideas I want to support. But more importantly, I’m skimming through the <a href="https://apple.github.io/swift-evolution/">Proposals</a> that are officially in review or even accepted. Of course, I’m reading <a href="https://www.hackingwithswift.com/articles/247/whats-new-in-swift-5-6">Paul Hudson great write-ups</a> whenever a new Swift version is released, but for an informed long-term decision-making that’s too late for me.</p><p>Actually, <a href="https://twitter.com/twostraws">Paul Hudson</a> used to talk about new and coming Swift features together with <a href="https://twitter.com/ericasadun">Erica Sadun</a> in the <a href="https://podcasts.apple.com/us/podcast/swift-over-coffee/id1435076502"><strong>Swift over Coffee</strong></a> podcast. Likewise, <a href="https://twitter.com/jesse_squires">Jesse Squires</a> and <a href="https://twitter.com/simjp">JP Simard</a> used to talk about Swift Evolution proposals in their <a href="https://podcasts.apple.com/us/podcast/swift-unwrapped/id1209817203"><strong>Swift Unwrapped</strong></a> podcast. But both stopped recording new episodes after their WWDC episodes in 2020 and 2021, respectively.</p><p>The same <a href="https://twitter.com/jesse_squires">Jesse Squires</a> had also started the <a href="https://swiftweeklybrief.com/"><strong>Swift Weekly Brief</strong></a> newsletter in 2015 right after Swift was open-sourced, to stay up-to-date with the latest in Swift Evolution. The <a href="https://github.com/SwiftWeekly/swiftweekly.github.io">community-driven</a> newsletter was later maintained by <a href="https://twitter.com/BasThomas">Bas Broek</a> and most recently by <a href="https://twitter.com/fassko">Kristaps Krinbergs</a>. But unfortunately, it ended a few months ago with <a href="https://swiftweeklybrief.com/issue-200/">Issue #200</a> on December, 16th 2021.</p><p>So, here we are, me trying to fill the gap with a monthly summary of what interesting developments I’ve come across in the Swift forums.</p><hr /><blockquote><p>ℹ️ The following list is just <strong>a selection of proposals</strong> I think are interesting to app developers. For a full list, see <a href="https://apple.github.io/swift-evolution/">🌐this website</a>.info</p></blockquote><h3 id="accepted-proposals">Accepted Proposals</h3><h4 id="se-0329-clock-instant-and-duration"><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0329-clock-instant-duration.md">SE-0329: Clock, Instant, and Duration</a></h4><p><strong>Problem:</strong><br />We have many different types to measure &amp; do calculations with continuous time: <code>Date</code>, <code>TimeInterval</code>, <code>DispatchTime</code>, <code>DispatchTimeInterval</code>, …<br />Currently, there’s no unified concept of time in all frameworks. Also, <code>TimeInterval</code> is technically just a <code>typealias</code> for <code>Double</code> and is implicitly respresenting time in the unit of “seconds”. There’s no explicitness to the unit, nor are there any APIs available to convert easily between units (like <a href="https://github.com/Flinesoft/HandySwift/blob/main/Sources/HandySwift/Extensions/TimeIntervalExt.swift">here</a>). Also, as a floating-type, <code>TimeInterval</code> is susceptible to <a href="https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html#689">rounding errors</a>.</p><p><strong>Solution:</strong><br />Three new types will be introduced to unify the concepts of time in Swift:</p><pre><code class="language-Swift">public struct Duration {
  public var components: (seconds: Int64, attoseconds: Int64)
}</code></pre><p><code>Duration</code> prevents any inexact rounding errors like with <code>Double</code> by storing the time interval in two <code>Int64</code> variables: <code>seconds</code> and <code>attoseconds</code>. But this internal representation will probably never be accessed directly, as many convenience extensions are provided, such as a static <code>.seconds</code> method to write readable code like <code>let duration: Duration = .seconds(5)</code>. <code>Duration</code> also supports arithmetic operations such as <code>+</code>, <code>—</code> or <code>*</code> and <code>/</code>.</p><pre><code class="language-Swift">public protocol InstantProtocol {
  func advanced(by duration: Duration) -&gt; Self
  func duration(to other: Self) -&gt; Duration
}</code></pre><p>Types adhering to the <code>InstantProtocol</code>, such as <code>Date</code> in the future, basically represent an instant in time and have APIs to interact with the <code>Duration</code> type. <code>Date</code>s <code>addingTimeInterval()</code> method gets unified to <code>advanced(by:)</code> and <code>timeIntervalSince()</code> method gets unified to <code>duration(to:)</code>. Types adhering to <code>InstantProtocol</code> will also support the arithmetic operations <code>+</code> and <code>-</code>.</p><pre><code class="language-Swift">public protocol Clock {
  associatedtype Instant: InstantProtocol
  
  var now: Instant { get }
  func sleep(until deadline: Instant, tolerance: Instant.Duration?) async throws 
}

extension Clock {
  func measure(_ work: () async throws -&gt; Void) reasync rethrows -&gt; Instant.Duration
}</code></pre><p>Lastly, types adhering to the <code>Clock</code> protocol, like a new <code>UTCClock</code> type in Foundation in the future, will provide a way to get the current time instant via a static <code>.now</code> computed property (so <code>UTCClock.now</code> will be equal to <code>Date()</code>). Also, they will provide an asynchronous <code>sleep(until:tolerance:)</code> function. An extra convenience function <code>measure(work:) -&gt; Duration</code> will help stopping the time of executing a chunk of code — neat! The <code>Clock</code> protocol will also make it easier to create <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0329-clock-instant-duration.md#example-custom-clock">a custom type</a> for <a href="https://github.com/pointfreeco/combine-schedulers#testscheduler">controlling time in tests</a>.</p><p><strong>Expected in:</strong> ~Swift 5.7 (my guess based on <a href="https://github.com/apple/swift/pull/40609">merged PR</a> from Feb 16th)</p><h4 id="se-0339-module-aliasing-for-disambiguation"><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0339-module-aliasing-for-disambiguation.md">SE-0339: Module Aliasing For Disambiguation</a></h4><p><strong>Problem:</strong><br />In SwiftPM, when including two dependencies that both had a target named <code>Utils</code> for example, currently we would get a name collision error. To solve this, we would need to edit one of the dependencies (e.g. by forking) and rename the <code>Utils</code> target in one to something else, like <code>GameUtils</code>.</p><p><strong>Solution:</strong><br />Instead of editing the dependency, we will be able to just provide an alias name to a specific packages dependency right in our projects <code>Package.swift</code> manifest file by using the new <code>moduleAliases</code> parameter like so:</p><pre><code class="language-Swift">.target(
  name: &quot;App&quot;,
  dependencies: [
    .product(name: &quot;Game&quot;, moduleAliases: [&quot;Utils&quot;: &quot;GameUtils&quot;], package: &quot;swift-game&quot;), 
    .product(name: &quot;Utils&quot;, package: &quot;swift-draw&quot;), 
  ]
)</code></pre><p><strong>Expected in:</strong> ~Swift 5.7 (my guess based on <a href="https://github.com/apple/swift-package-manager/pull/4023">merged PR</a> from Feb 9th)</p><h4 id="se-0341-opaque-parameter-declarations"><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0341-opaque-parameters.md">SE-0341: Opaque Parameter Declarations</a></h4><p><strong>Problem:</strong><br />Today, we can just return <code>some View</code> from functions instead of having to specify a generic type <code>&lt;T: View&gt;</code>. This kind of return type with the <code>some</code> keyword is called an “opaque type” (see <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0244-opaque-result-types.md">SE-0244</a>). It saves us boilerplate code. If you’re like me, you might have tried to specify <code>some View</code> in parameters of functions as well, when trying to extract some SwiftUI code from a <code>body</code> that got too long. But it doesn’t currently compile…</p><p><strong>Solution:</strong><br />In the future it will compile! For example, instead of writing this:</p><pre><code class="language-Swift">func horizontal&lt;V1: View, V2: View&gt;(_ v1: V1, _ v2: V2) -&gt; some View {
  HStack {
    v1
    v2
  }
}</code></pre><p>You’ll be able to write this (note that no generic types are needed):</p><pre><code class="language-Swift">func horizontal(_ v1: some View, _ v2: some View) -&gt; some View {
  HStack {
    v1
    v2
  }
}</code></pre><p><strong>Expected in:</strong> Swift 5.7 (confirmed in ‘Status’ field)</p><h3 id="proposals-in-review">Proposals In Review</h3><blockquote><p>ℹ️ Note that for the following proposals you can still provide feedback (by clicking the “Review” link in the proposal). Also changes are possible. And in rare cases (&lt;10%), they might even <a href="https://apple.github.io/swift-evolution/#?status=rejected">get rejected</a>.</p></blockquote><h4 id="se-0344-distributed-actor-runtime"><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0344-distributed-actor-runtime.md">SE-0344: Distributed Actor Runtime</a></h4><p><strong>Problem:</strong><br />This is a large one — so large it even has a Table of Contents! — and I don’t fully understand it yet myself. But together with <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0336-distributed-actor-isolation.md">SE-0336 Distributed Actor Isolation</a>, which was accepted back in January, it seems this is one of the more amazing and unique features Swift will provide compared to other modern languages.</p><p>The problem, as far as I understand, is that the newly introduced <code>actor</code> type provides safety only on a <em>local</em>environment level, as in “safety for access between different threads on the same process of one machine”. (If you’re new to <code>actor</code>s in general, Paul Hudson has a great write-up <a href="https://www.hackingwithswift.com/quick-start/concurrency/what-is-an-actor-and-why-does-swift-have-them">on that, too</a>.) An <code>actor</code> type does not provide safety in accessing data between different processes or even different machines though. This makes writing correct code accessing the same data across machines hard, for example in client-server situations or in live peer-to-peer communication.</p><p><strong>Solution:</strong><br />Besides the new <code>distributed actor</code> type and <code>DistributedActor</code> protocol accepted in <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0336-distributed-actor-isolation.md">SE-0336</a>, a new <code>DistributedActorSystem</code> protocol is introduced here which basically defines details about how communication between different environments happens. If I understand it correctly, different implementations for different purposes can be provided, such as one for cross-process communication, one for clustering and another for client-server communication. In the end, we would be able to define a function as being <code>distributed</code> much like we can now define functions to be <code>async</code> like so:</p><pre><code class="language-Swift">distributed actor Game {
  var state: GameState = ...

  // players can be located on different nodes
  var players: Set&lt;Player&gt; = []

  distributed func playerJoined(_ player: Player) {
    others.append(player)
    if others.count &gt;= 2 { // we need 2 other players to start a game
      Task { try await self.start() }
    }
  }

  func start() async throws { ... }
}</code></pre><p>Then all calls into such functions need to be <code>await</code>ed for like here:</p><pre><code class="language-Swift">await game.playerJoined(newPlayer)</code></pre><p>So the overall goal of this is to make distributed environment access to data (nearly) as simple as thread-safe access to data has become with <code>actor</code>s. Does this hold the potential to even eliminate all our client-server networking code in our apps, provided that the server is implemented in Swift, too? I have no idea. And from what I hear, that’s not the main goal here. But it sounds like a very interesting area to keep an eye on in the coming years ahead for sure!</p><p><strong>Expected in:</strong> Swift 5.8 or later (partially implemented, feature flag on <code>main</code>)</p><h4 id="se-0345-if-lethttpsgithubcomappleswift-evolutionblobmainproposals0345-if-let-shorthandmd-shorthand-for-shadowing-an-existing-optional-variable"><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0345-if-let-shorthand.md">SE-0345: </a><code>[if let](https://github.com/apple/swift-evolution/blob/main/proposals/0345-if-let-shorthand.md)</code><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0345-if-let-shorthand.md"> shorthand for shadowing an existing optional variable</a></h4><p><strong>Problem:</strong><br />Optional binding as in <code>if let foo = foo { … }</code> is extremely common in Swift code. Repeating the same identifier twice is verbose and can lead to weird indentation situations when line limits are reached with long variable names. Solving this verbosity was already <a href="https://forums.swift.org/t/if-let-shortcut-syntax/56">requested back in 2015</a> by the community, shortly after Swift had been open sourced.</p><p><strong>Solution:</strong><br />Instead of repeating the variable name like in this code:</p><pre><code class="language-Swift">let someLengthyVariableName: Foo? = ...
let anotherImportantVariable: Bar? = ...

if let someLengthyVariableName = someLengthyVariableName, let anotherImportantVariable = anotherImportantVariable {
    ...
}</code></pre><p>We would be able to get rid of the right <code>= repeatingVariableName</code> part like so:</p><pre><code class="language-Swift">let someLengthyVariableName: Foo? = ...
let anotherImportantVariable: Bar? = ...

if let someLengthyVariableName, let anotherImportantVariable {
    ...
}</code></pre><p><strong>Expected in:</strong> ~Swift 5.7 (<a href="https://github.com/apple/swift/pull/40694/files">small PR</a> 👍, but <a href="https://forums.swift.org/t/se-0345-if-let-shorthand-for-shadowing-an-existing-optional-variable/55805">Review feedback is quite mixed</a>)</p><h4 id="se-0346-lightweight-same-type-requirements-for-primary-associated-types"><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0346-light-weight-same-type-syntax.md">SE-0346: Lightweight same-type requirements for primary associated types</a></h4><p><strong>Problem:</strong><br />Have you ever written a function for a concrete type, like for <code>Array</code>:</p><pre><code class="language-Swift">func concatenate(_ lhs: Array&lt;String&gt;, _ rhs: Array&lt;String&gt;) -&gt; Array&lt;String&gt; {
  ...
}</code></pre><p>And then later you wanted to generalize it over all types conforming to <code>Sequence</code> to also make it work with <code>Set</code>, <code>Dictionary</code> and more like this:</p><pre><code class="language-Swift">func concatenate&lt;S : Sequence&gt;(_ lhs: S, _ rhs: S) -&gt; S where S.Element == String {
  ...
}</code></pre><p>You find it weird that we specify the <code>where</code> clause at the end? And you find it cumbersome to lookup the name of the <code>associatedtype</code> (here <code>Element</code>) within the implementation of the <code>Sequence</code> protocol? These and other annoyances around generics exist at the moment, see also <a href="https://forums.swift.org/t/improving-the-ui-of-generics/22814/1">this forum thread</a>.</p><p><strong>Solution:</strong><br />Consistent to how we write generic type requirements for concrete types like <code>Array&lt;String&gt;</code>, we would be able to specify the associated type right in-place:</p><pre><code class="language-Swift">func concatenate&lt;S : Sequence&lt;String&gt;&gt;(_ lhs: S, _ rhs: S) -&gt; S {
  ...
}</code></pre><p>We could emit the <code>where</code> in more places, all these pairs would be equivalent:</p><pre><code class="language-Swift">// Extensions
extension Collection where Element == String { ... }
extension Collection&lt;String&gt; { ... }

// Inheritance
protocol TextBuffer : Collection where Element == String { ... }
protocol TextBuffer : Collection&lt;String&gt; { ... }

// Nested Opaque Parameters
func sort&lt;C : Collection, E : Equatable&gt;(elements: inout C) {} where C.Element == E
func sort(elements: inout some Collection&lt;some Equatable&gt;) {}</code></pre><p><strong>Expected in:</strong> Swift 5.7 or later (partially implemented, feature flag on <code>main</code>)</p><hr /><blockquote><p>✨ Want to see your ad here? Contact me at <a href="mailto:ads@fline.dev">ads@fline.dev</a> to get in touch.</p></blockquote><hr /><h3 id="other-developments-worth-mentioning">Other Developments worth Mentioning</h3><p>Did you know that <a href="https://twitter.com/clattner_llvm">Chris Lattner</a>, the <a href="https://oleb.net/2019/chris-lattner-swift-origins/">original author of Swift</a>, has decided to leave the Swift core team and even the Swift Evolution community? If you haven’t come across this news already, I recommend reading <a href="https://forums.swift.org/t/core-team-to-form-language-workgroup/55455/6">his detailed post</a> on the reasons why he’s leaving, which is a unique chance to get some detailed insights in how Swift has been developed in the past.</p><p>Just a few chosen (negative) quotes from his post:</p><blockquote><p>… the core team is a toxic environment in the meetings themselves.</p></blockquote><blockquote><p>… after being insulted and yelled at over WebEx (not for the first time, and not just one core team member) …</p></blockquote><blockquote><p>… a complicated situation and many pressures (including lofty goals, fixed schedules, deep bug queues to clear, internal folks that want to review/design things before the public has access to them, …)</p></blockquote><p>But he does end on a positive note, which I totally agree with:</p><blockquote><p>I think that Swift is a phenomenal language and has a long and successful future ahead …</p></blockquote><blockquote><p>I think that a healthy and inclusive community will continue to benefit the design and evolution of Swift.</p></blockquote><p>I personally am very thankful for all Chris has done for our community and wish him all the best for his future! It’s worth mentioning that there were some <a href="https://forums.swift.org/t/core-team-to-form-language-workgroup/55455">deeper structural changes</a> to the Swift core team announced already that might help improve the situation. As for the struggles he seemed to have had, it’s hard to comment on them without further details.</p><p>Knowing nothing about Apples internal plans and the discussions of the core team, I am still optimistic about the community aspect of Swift in the years to come. While Apple is still far away from being a transparent company, from my experience they are trying to open up more and more recently on developer topics. For example, they <a href="https://github.com/apple/swift-docc">open sourced DocC</a> last year at WWDC. They also open sourced the <a href="https://github.com/apple/swift-markdown">Markdown parser</a> they use in SwiftUI. And just this week, they even <a href="https://www.swift.org/blog/website-open-source/">open sourced the swift.org website</a> itself. So things are going in the right direction. Sometimes it might feel like two steps forward, one step back. But even that is still a step forward overall!</p><p>I’m looking forward to what else the future holds for us Swift developers. A lot is going on for sure. And I hope that this article helped you explore some of it. Follow me if you don’t want to miss future Swift Evolution Monthly posts.</p><blockquote><p>💁🏻‍♂️ <strong>Enjoyed this article? Check out my app <strong>RemafoX</strong>!</strong>
A native Mac app that integrates with Xcode to help translate <strong>your</strong> app.
<a href="https://apps.apple.com/app/apple-store/id1605635026?pt=549314&ct=fline.dev&mt=8&ref=fline.dev"><strong>Get it now</strong></a> to save time during development &amp; make localization easy.</p></blockquote>]]></content:encoded>
<media:thumbnail url="https://evolutionkit.dev/assets/images/blog/swift-evolution-monthly-first-issue/hero.webp"/>
</item>
</channel>
</rss>