{"id":49831,"date":"2025-10-29T14:15:52","date_gmt":"2025-10-29T18:15:52","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=49831"},"modified":"2025-11-03T15:48:53","modified_gmt":"2025-11-03T20:48:53","slug":"swift-6-2","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2025\/10\/29\/swift-6-2\/","title":{"rendered":"Swift 6.2"},"content":{"rendered":"<p><a href=\"https:\/\/www.swift.org\/blog\/swift-6.2-released\/\">Holly Borla<\/a>:<\/p>\n<blockquote cite=\"https:\/\/www.swift.org\/blog\/swift-6.2-released\/\"><p><a href=\"https:\/\/developer.apple.com\/documentation\/swift\/inlinearray\"><code>InlineArray<\/code><\/a> is a new fixed-size array with inline storage for elements, which can be stored on the stack or directly within other types without additional heap allocation.<\/p><p>[&#8230;]<\/p><p>The new <a href=\"https:\/\/developer.apple.com\/documentation\/swift\/span?changes=_8\"><code>Span<\/code><\/a> type offers safe, direct access to contiguous memory. Span maintains memory safety by ensuring the memory remains valid while you&rsquo;re using it.<\/p><p>[&#8230;]<\/p><p>Swift 6.2 introduces <em>opt-in strict memory safety<\/em>, which flags uses of unsafe constructs, so you can replace them with safe alternatives or explicitly acknowledge them in source code.<\/p><p>[&#8230;]<\/p><p>Swift 6.2 significantly improves clean build times for projects that use macro-based APIs.<\/p><\/blockquote>\n\n<p>Most of these proposals have been previously discussed here. Strict memory safety is in <a href=\"https:\/\/github.com\/swiftlang\/swift-evolution\/blob\/main\/proposals\/0458-strict-memory-safety.md\">SE-0458<\/a>:<\/p>\n<blockquote cite=\"https:\/\/github.com\/swiftlang\/swift-evolution\/blob\/main\/proposals\/0458-strict-memory-safety.md\"><p>This proposal introduces an opt-in strict memory safety checking mode that identifies all uses of unsafe behavior within the given module. There are several parts to this change:<\/p><ul><li>A compiler flag <code>-strict-memory-safety<\/code> that enables warnings for all uses of unsafe constructs within a given module. All warnings will be in the diagnostic group <code>StrictMemorySafety<\/code>, enabling precise control over memory-safety-related warnings per <a href=\"https:\/\/github.com\/swiftlang\/swift-evolution\/blob\/main\/proposals\/0443-warning-control-flags.md\">SE-0443<\/a>. When strict memory safety is enabled, the <code>StrictMemorySafety<\/code> feature will be set: <code>#if hasFeature(StrictMemorySafety)<\/code> can be used to detect when Swift code is being compiled in this mode.<\/li><li>An attribute <code>@unsafe<\/code> that indicates that a declaration is unsafe to use. Such declarations may use unsafe constructs within their signatures.<\/li><li>A corresponding attribute <code>@safe<\/code> that indicates that a declaration whose signature contains unsafe constructs is actually safe to use. For example, the <code>withUnsafeBufferPointer<\/code> method on <code>Array<\/code> has an unsafe type in its signature (<code>self<\/code>), but is actually safe to use because it handles safety for the unsafe buffer pointer it vends to its closure argument. The closure itself will need to handle the unsafety when using that unsafe buffer pointer.<\/li><li>An <code>unsafe<\/code> expression that marks any use of unsafe constructs in an expression, much like <code>try<\/code> and <code>await<\/code>.<\/li><li>Standard library annotations to identify unsafe declarations.<\/li><\/ul><\/blockquote>\n\n<p><a href=\"https:\/\/github.com\/swiftlang\/swift-evolution\/blob\/main\/proposals\/0477-default-interpolation-values.md\">SE-0477<\/a>:<\/p>\n<blockquote cite=\"https:\/\/github.com\/swiftlang\/swift-evolution\/blob\/main\/proposals\/0477-default-interpolation-values.md\">\n<p>A new string interpolation syntax for providing a default string when interpolating an optional value.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/useyourloaf.com\/blog\/swift-default-value-in-string-interpolations\/\">Keith Harrison<\/a>:<\/p>\n<blockquote cite=\"https:\/\/useyourloaf.com\/blog\/swift-default-value-in-string-interpolations\/\">\n<p>One issue is that I&rsquo;ve been unable to get this to work with localization. The problem seems to be that <code>LocalizedStringKey<\/code> doesn't&rsquo;t support the default value parameter.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/www.hackingwithswift.com\/articles\/277\/whats-new-in-swift-6-2\">Paul Hudson<\/a> (<a href=\"https:\/\/mastodon.social\/@twostraws\/114479690308964815\">Mastodon<\/a>, <a href=\"https:\/\/news.ycombinator.com\/item?id=43940539\">Hacker News<\/a>):<\/p>\n<blockquote cite=\"https:\/\/www.hackingwithswift.com\/articles\/277\/whats-new-in-swift-6-2\"><p><a href=\"https:\/\/github.com\/swiftlang\/swift-evolution\/blob\/main\/proposals\/0451-escaped-identifiers.md\">SE-0451<\/a> dramatically expands the range of characters we can use to create identifiers &#x2013; the names of variables, functions, enum cases and similar &#x2013; so we can name them pretty much however we want when placed inside backticks.<\/p><p>[&#8230;]<\/p><p><a href=\"https:\/\/github.com\/swiftlang\/swift-evolution\/blob\/main\/proposals\/0459-enumerated-collection.md\">SE-0459<\/a> makes the type returned by <code>enumerated()<\/code> conform to <code>Collection<\/code>.<\/p><p>[&#8230;]<\/p><p><a href=\"https:\/\/github.com\/swiftlang\/swift-evolution\/blob\/main\/proposals\/0479-method-and-initializer-keypaths.md\">SE-0479<\/a> extends Swift&rsquo;s key paths to support methods alongside the existing support for properties and subscripts, which, along with <a href=\"https:\/\/github.com\/swiftlang\/swift-evolution\/blob\/main\/proposals\/0438-metatype-keypath.md\">SE-0438<\/a> introduced in Swift 6.1, promises to round out what key paths can do.<\/p><p>[&#8230;]<\/p><p><a href=\"https:\/\/github.com\/swiftlang\/swift-evolution\/blob\/main\/proposals\/0419-backtrace-api.md\">SE-0419<\/a> introduces a new <code>Backtrace<\/code> struct, which is capable of capturing data about the call stack of our app at any given moment &#x2013; the exact sequence of function calls leading up to the current point.<\/p><p>[&#8230;]<\/p><p><a href=\"https:\/\/github.com\/swiftlang\/swift-evolution\/blob\/main\/proposals\/0448-regex-lookbehind-assertions.md\">SE-0448<\/a> expands Swift&rsquo;s regular expression support to include <em>lookbehind assertions<\/em>, which allow us to check if a specific pattern appears immediately before the current position in the string, <em>without<\/em> including it in the matched text.<\/p><p>[&#8230;]<\/p><p>It&rsquo;s <a href=\"https:\/\/github.com\/swiftlang\/swift-evolution\/blob\/main\/proposals\/0476-abi-attr.md\">SE-0476<\/a>, which introduces a new <code>@abi<\/code> attribute that makes it easier for ABI-stable library authors to make changes to their libraries without breaking things.<\/p><\/blockquote>\n\n<p><a href=\"https:\/\/mastodon.social\/@cocoawithlove\/114481176126553670\">Matt Gallagher<\/a> (<a href=\"https:\/\/github.com\/mattgallagher\/CwlDemangle\">CwlDemangle<\/a>):<\/p>\n<blockquote cite=\"https:\/\/mastodon.social\/@cocoawithlove\/114481176126553670\"><p>It looks like Swift 6.2 will <em>finally<\/em> let us access the built-in Swift demangling so we can turn runtime mangled names into something human readable without resorting to half-assed third party libraries (like my own CwlDemangle).<\/p><p>Technically, the demangling is part of the new <code>Backtrace<\/code> API but it offers <code>SymbolicatedBacktrace.Symbol<\/code> with a lazily evaluated <code>name<\/code> that performs demangling on the <code>rawName<\/code>.<\/p><p>It doesn&rsquo;t expose <code>DemangleOptions<\/code> but it&rsquo;s a huge improvement.<\/p><\/blockquote>\n\n<p>Swift 6.2 also includes some other big features, which I&rsquo;m going to write separate posts about:<\/p>\n\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2025\/10\/29\/swift-6-2-notificationcenter-messages\/\">NotificationCenter Messages<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2025\/10\/30\/swift-6-2-subprocess\/\">Subprocess<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2025\/10\/31\/swift-6-2-observations\/\">Observations<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2025\/11\/03\/swift-6-2-approachable-concurrency\/\">Approachable Concurrency<\/a><\/li>\n<\/ul>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2025\/09\/16\/xcode-26\/\">Xcode 26<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2025\/05\/01\/swift-proposal-weak-let\/\">Swift Proposal: weak let<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2025\/03\/21\/swift-testing-proposal-exit-tests\/\">Swift Testing Proposal: Exit Tests<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2025\/03\/19\/lifetime-dependencies-in-swift-6-2-and-beyond\/\">Lifetime Dependencies in Swift 6.2 and Beyond<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2025\/03\/03\/swift-6-1\/\">Swift 6.1<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2025\/02\/17\/swift-proposal-inlinearray\/\">Swift Proposal: InlineArray<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2024\/12\/05\/swift-proposal-precise-control-flags-over-compiler-warnings\/\">Swift Proposal: Precise Control Flags Over Compiler Warnings<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2024\/04\/12\/swift-for-c-practitioners\/\">Swift for C++ Practitioners<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2023\/11\/14\/on-crash-backtraces-in-swift\/\">On-Crash Backtraces in Swift<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2016\/05\/09\/demangling-swift-with-swift\/\">Demangling Swift With Swift<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Holly Borla: InlineArray is a new fixed-size array with inline storage for elements, which can be stored on the stack or directly within other types without additional heap allocation.[&#8230;]The new Span type offers safe, direct access to contiguous memory. Span maintains memory safety by ensuring the memory remains valid while you&rsquo;re using it.[&#8230;]Swift 6.2 introduces [&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":"2025-10-29T18:15:56Z","apple_news_api_id":"0617eacd-1157-44ad-9fd3-f6c5dd5de7e6","apple_news_api_modified_at":"2025-11-03T20:48:55Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAACA==","apple_news_api_share_url":"https:\/\/apple.news\/ABhfqzRFXRK2f0_bF3V3n5g","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":[31,2741,46,309,30,2742,941,571,71,234,2854,901],"class_list":["post-49831","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-ios","tag-ios-26","tag-languagedesign","tag-localization","tag-mac","tag-macos-tahoe-26","tag-macros","tag-memory-management","tag-programming","tag-regex","tag-swift-foundation","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/49831","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=49831"}],"version-history":[{"count":10,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/49831\/revisions"}],"predecessor-version":[{"id":49882,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/49831\/revisions\/49882"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=49831"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=49831"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=49831"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}