{"id":34039,"date":"2021-10-28T14:01:37","date_gmt":"2021-10-28T18:01:37","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=34039"},"modified":"2022-05-05T13:45:00","modified_gmt":"2022-05-05T17:45:00","slug":"swift-concurrency-for-older-os-versions","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2021\/10\/28\/swift-concurrency-for-older-os-versions\/","title":{"rendered":"Swift Concurrency for Older OS Versions"},"content":{"rendered":"<p><a href=\"https:\/\/developer.apple.com\/documentation\/xcode-release-notes\/xcode-13_2-release-notes\">Xcode 13.2 Beta<\/a>:<\/p>\n<blockquote cite=\"https:\/\/developer.apple.com\/documentation\/xcode-release-notes\/xcode-13_2-release-notes\">\n<p>You can now use Swift Concurrency in applications that deploy to macOS 10.15, iOS 13, tvOS 13, and watchOS 6 or newer. This support includes async\/await, actors, global actors, structured concurrency, and the task APIs.<\/p>\n<\/blockquote>\n\n<p>See also: <a href=\"https:\/\/forums.swift.org\/t\/swift-concurrency-back-deployment\/51908\">Swift concurrency back deployment<\/a>. The <a href=\"https:\/\/forums.swift.org\/t\/swift-5-5-has-serious-stack-corruption-bugs\/52344\/46\">memory corruption issues<\/a> are <a href=\"https:\/\/forums.swift.org\/t\/swift-concurrency-back-deployment\/51908\/28\">apparently<\/a> fixed, too.<\/p>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2021\/09\/21\/swift-5-5-released\/\">Swift 5.5 Released<\/a><\/li>\n<\/ul>\n\n<p id=\"swift-concurrency-for-older-os-versions-update-2021-10-29\">Update (2021-10-29): <a href=\"https:\/\/www.swiftbysundell.com\/articles\/making-async-system-apis-backward-compatible\/\">John Sundell<\/a>:<\/p>\n<blockquote cite=\"https:\/\/www.swiftbysundell.com\/articles\/making-async-system-apis-backward-compatible\/\">\n<p>Although Swift 5.5&rsquo;s new concurrency system is <a href=\"https:\/\/www.swiftbysundell.com\/special\/swift-concurrency-backward-compatibility\">becoming backward compatible in Xcode 13.2<\/a>, some of the built-in system APIs that make use of these new concurrency features are still only available on iOS 15, macOS Monterey, and the rest of Apple&rsquo;s 2021 operating systems.<\/p>\n<p>[&#8230;]<\/p>\n<p>Thankfully, the above problem is something that we can fix ourselves, since Swift&rsquo;s new concurrency system ships with a <a href=\"https:\/\/www.swiftbysundell.com\/articles\/connecting-async-await-with-other-swift-code\/#retrofitting-existing-apis-with-asyncawait-support\">continuation mechanism<\/a> that lets us retrofit existing code with async\/await support.<\/p><p>Here&rsquo;s how we could use that mechanism to replicate the above async\/await-powered <code>URLSession<\/code> API in order to make it available all the way back to iOS 13[&#8230;]<\/p>\n<\/blockquote>\n\n<p id=\"swift-concurrency-for-older-os-versions-update-2021-12-16\">Update (2021-12-16): <a href=\"https:\/\/twitter.com\/dimitribouniol\/status\/1470798102189658114\">Dimitri Bouniol<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/dimitribouniol\/status\/1470798102189658114\">\n<p>Now that Swift&rsquo;s concurrency system is backwards compatible with iOS 13\/Catalina, here are a few packages you might want to check out!<\/p>\n<\/blockquote>\n\n<p id=\"swift-concurrency-for-older-os-versions-update-2022-01-31\">Update (2022-01-31): <a href=\"https:\/\/twitter.com\/dgregor79\/status\/1486936460259250179\">Doug Gregor<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/dgregor79\/status\/1486936460259250179\">\n<p>For folks using #SwiftLang concurrency on older Apple platforms, Xcode 13.3 beta addresses launch-time crashes reported on earlier OS versions (eg iOS 12, macOS 10.14).<\/p>\n<\/blockquote>\n\n<p id=\"swift-concurrency-for-older-os-versions-update-2022-04-27\">Update (2022-04-27): <a href=\"https:\/\/twitter.com\/olebegemann\/status\/1519341491734425602\">Ole Begemann<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/olebegemann\/status\/1519341491734425602\">\n<p>Boy, this back-deployment of Swift features is complicated.<\/p>\n<p>tl;dr: Critical concurrency bug fixes that shipped in iOS 15.4\/macOS 12.3 <a href=\"https:\/\/forums.swift.org\/t\/new-xcode-old-libswift-concurrency-dylib\/56754\">don&rsquo;t magically make it<\/a> into the concurrency runtime used on iOS 13\/14.<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Xcode 13.2 Beta: You can now use Swift Concurrency in applications that deploy to macOS 10.15, iOS 13, tvOS 13, and watchOS 6 or newer. This support includes async\/await, actors, global actors, structured concurrency, and the task APIs. See also: Swift concurrency back deployment. The memory corruption issues are apparently fixed, too. Previously: Swift 5.5 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2021-10-28T18:01:40Z","apple_news_api_id":"f2c0a155-4553-4f71-a56b-7f15d87eff43","apple_news_api_modified_at":"2022-05-05T17:45:20Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAABA==","apple_news_api_share_url":"https:\/\/apple.news\/A8sChVUVTT3Gla38V2H7_Qw","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":[800,1667,1837,1666,1891,71,2200,901],"class_list":["post-34039","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-concurrency","tag-ios-13","tag-ios-14","tag-macos-10-15","tag-macos-11-0","tag-programming","tag-swift-concurrency","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/34039","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=34039"}],"version-history":[{"count":5,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/34039\/revisions"}],"predecessor-version":[{"id":35714,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/34039\/revisions\/35714"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=34039"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=34039"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=34039"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}