{"id":45014,"date":"2024-09-19T15:22:04","date_gmt":"2024-09-19T19:22:04","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=45014"},"modified":"2024-12-17T09:13:04","modified_gmt":"2024-12-17T14:13:04","slug":"swift-6","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2024\/09\/19\/swift-6\/","title":{"rendered":"Swift 6"},"content":{"rendered":"<p><a href=\"https:\/\/www.swift.org\/blog\/announcing-swift-6\/\">Holly Borla<\/a> (<a href=\"https:\/\/news.ycombinator.com\/item?id=41571606\">Hacker News<\/a>, <a href=\"https:\/\/lobste.rs\/s\/ekcutg\/announcing_swift_6\">Lobsters<\/a>):<\/p>\n<blockquote cite=\"https:\/\/www.swift.org\/blog\/announcing-swift-6\/\"><p>Swift 6 marks the start of the journey to make data-race safety dramatically easier. The usability of data-race safety remains an area of active development, and your feedback will help shape future improvements.<\/p><p>Swift 6 also comes with a new <a href=\"https:\/\/developer.apple.com\/documentation\/synchronization\">Synchronization library<\/a> for low-level concurrency APIs, including atomic operations and a new mutex API.<\/p><p>[&#8230;]<\/p><p>Swift 6 introduces a number of productivity enhancements, including <a href=\"https:\/\/developer.apple.com\/documentation\/swift\/sequence\/count(where:)\"><code>count(where:)<\/code><\/a> to streamline counting the number of elements in a sequence that satisfy a predicate, <a href=\"https:\/\/www.swift.org\/blog\/pack-iteration\/\">pack iteration<\/a> for writing natural <code>for<\/code>-loops over the elements in a value parameter pack, access control for imports to keep implementation details from leaking into your public APIs, <code>@attached(body)<\/code> macros for synthesizing and augmenting function implementations, expression macros as default arguments, and more.<\/p><p>You can find a complete list of language proposals that were accepted through the <a href=\"https:\/\/github.com\/swiftlang\/swift-evolution\">Swift Evolution<\/a> process and implemented in Swift 6 on the <a href=\"https:\/\/www.swift.org\/swift-evolution\/#?version=6.0\">Swift Evolution dashboard<\/a>.<\/p><p>[&#8230;]<\/p><p>Swift 6 unifies the implementation of <a href=\"https:\/\/developer.apple.com\/documentation\/foundation\/\">Foundation<\/a> across all platforms. The modern, portable Swift implementation provides consistency across platforms, it&rsquo;s more robust, and it&rsquo;s open source. macOS and iOS started using the Swift implementation of Foundation alongside Swift 5.9, and Swift 6 brings these improvements to Linux and Windows.<\/p><\/blockquote>\n\n<p><a href=\"https:\/\/x.com\/rudrankriyam\/status\/1830713280312287679\">Rudrank Riyam<\/a>:<\/p>\n<blockquote cite=\"https:\/\/x.com\/rudrankriyam\/status\/1830713280312287679\"><p>I <a href=\"https:\/\/www.rudrank.com\/exploring-swift-static-property-shared-is-not-concurrency-safe-because-non-sendable-type-may-have-shared-mutable-state\/\">started documenting<\/a> my learnings about Swift 6 errors, the reasoning behind them, and how to fix them. The first one is:<\/p><blockquote>Static property &lsquo;shared&rsquo; is not concurrency-safe because non-&rsquo;Sendable&rsquo; type may have shared mutable state<\/blockquote><\/blockquote>\n\n<p><a href=\"https:\/\/mastodon.social\/@caseyliss\/113131070492375069\">Casey Liss<\/a>:<\/p>\n<blockquote cite=\"https:\/\/mastodon.social\/@caseyliss\/113131070492375069\"><p>Swift 6 strict concurrency checking may be the quickest and easiest way for me to feel like a dunce. &#x2639;&#xFE0F;<\/p><p>Half of these warnings I&rsquo;m just like &ldquo;uhhhhhh&#8230; wat&rdquo;.<\/p><p>I&rsquo;m sure I&rsquo;ll get there, but, gracious. &#x1F613; Gotta stop kicking that can though&#8230;<\/p><\/blockquote>\n\n<p><a href=\"https:\/\/mastodon.social\/@alexsteinerde\/113131078983351346\">Alexander Steiner<\/a>:<\/p>\n<blockquote cite=\"https:\/\/mastodon.social\/@alexsteinerde\/113131078983351346\">\n<p>Just wait until you have fixed all errors but the app is crashing at runtime randomly because of missing annotations in first-party frameworks.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/mastodon.social\/@sindresorhus\/113134179502612740\">Sindre Sorhus<\/a>:<\/p>\n<blockquote cite=\"https:\/\/mastodon.social\/@sindresorhus\/113134179502612740\">\n<p>My advice for updating to Swift 6:<\/p>\n<p>Turn on the switch, fix the easy stuff, turn it off again, and wait until next year. Apple will spend the next year making it easier to adopt complete concurrency.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/mastodon.social\/@simonbs\/113134243190175230\">Simon B. St&oslash;vring<\/a>:<\/p>\n<blockquote cite=\"https:\/\/mastodon.social\/@simonbs\/113134243190175230\">\n<p>I&rsquo;m leaning towards this plan too. Properly adopting concurrency in Swift 6 is way too convoluted. I can&rsquo;t imagine Apple won&rsquo;t get flooded with feedback from developers, pushing them to simplify it in a future version.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/chaos.social\/@dasdom\/113136367097531182\">dasdom<\/a>:<\/p>\n<blockquote cite=\"https:\/\/chaos.social\/@dasdom\/113136367097531182\"><p>Swift 6 is solving a problem I didn&rsquo;t encounter in 15 years of iOS development by providing me with lots of problems I didn&rsquo;t ask for.<\/p><\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2024\/09\/12\/xcode-16\/\">Xcode 16<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2024\/08\/29\/calling-async-code-synchronously-in-swift\/\">Calling async Code Synchronously in Swift<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2024\/07\/29\/actor-reentrancy-in-swift\/\">Actor Reentrancy in Swift<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2024\/07\/22\/swift-6-announced\/\">Swift 6 Announced<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2024\/03\/06\/swift-5-10\/\">Swift 5.10<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2023\/04\/27\/swift-foundation-preview\/\">Swift Foundation Preview<\/a><\/li>\n<\/ul>\n\n<p id=\"swift-6-update-2024-10-24\">Update (2024-10-24): <a href=\"https:\/\/talk.objc.io\/episodes\/S01E424-swift-6-concurrency-part-1\">objc.io<\/a>:<\/p>\n<blockquote cite=\"https:\/\/talk.objc.io\/episodes\/S01E424-swift-6-concurrency-part-1\">\n<p>We start a new macOS project to explore Swift 6&rsquo;s concurrency features.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/x.com\/jacobtechtavern\/status\/1849465879513161984\">Jacob Bartlett<\/a>:<\/p>\n<blockquote cite=\"https:\/\/x.com\/jacobtechtavern\/status\/1849465879513161984\">\n<p>Is Swift 6 strict concurrency going to be our Python 3 moment?<\/p>\n<\/blockquote>\n\n<p id=\"swift-6-update-2024-12-17\">Update (2024-12-17): <a href=\"https:\/\/toot.iamkonstantin.eu\/@konstantin\/113624674964989045\">Konstantin<\/a>:<\/p>\n<blockquote cite=\"https:\/\/toot.iamkonstantin.eu\/@konstantin\/113624674964989045\"><p>Today, I had my first &ldquo;this wouldn&rsquo;t have shipped if I had listened to @mattiem&rdquo; encounter with concurrency.<\/p><p>I was troubleshooting a strange, &ldquo;happens sometimes&rdquo; kind of bug and after several unsuccessful attempts to track it down, I thought to try enabling strict concurrency in Swift 6. And there it was, a beautiful build error &#x1F60D;.<\/p><p>So safety first from now on &#x1F9F7;.<\/p><\/blockquote>\n\n<p><a href=\"https:\/\/mastodon.social\/@Catfish_Man\/113631708603800900\">David Smith<\/a>:<\/p>\n<blockquote cite=\"https:\/\/mastodon.social\/@Catfish_Man\/113631708603800900\">\n<p>I had a similar experience with Thread Sanitizer in ObjC back in the day. It was a week before the WWDC keynote speech and 1 time in 10 a critical thing for said keynote would break in utterly mysterious ways. After 3 days of intensive debugging I finally tried the then-new-fangled TSAN; it pointed out I had bitfield tearing issues everywhere. A coworker made me a little &ldquo;Church of TSAN&rdquo; art I have to this day.<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Holly Borla (Hacker News, Lobsters): Swift 6 marks the start of the journey to make data-race safety dramatically easier. The usability of data-race safety remains an area of active development, and your feedback will help shape future improvements.Swift 6 also comes with a new Synchronization library for low-level concurrency APIs, including atomic operations and a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2024-09-19T19:22:06Z","apple_news_api_id":"f1446a33-c0a3-4929-93c4-cb3b8d8f508d","apple_news_api_modified_at":"2024-12-17T14:13:07Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAQ==","apple_news_api_share_url":"https:\/\/apple.news\/A8URqM8CjSSmTxMs7jY9QjQ","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[69,800,31,2586,46,30,2598,71,2200,901],"class_list":["post-45014","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-cocoa","tag-concurrency","tag-ios","tag-ios-18","tag-languagedesign","tag-mac","tag-macos-15-sequoia","tag-programming","tag-swift-concurrency","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/45014","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=45014"}],"version-history":[{"count":3,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/45014\/revisions"}],"predecessor-version":[{"id":46180,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/45014\/revisions\/46180"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=45014"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=45014"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=45014"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}