A Kotlin Style .copy Function for Swift Structs
Swift structs lack Kotlin data class's copy function, so mimicking immutable state updates requires boilerplate. A memberwise init plus a copy function with optional nil-defaulted params works until optional properties need to be set back to nil, and Swift can't reference self in default parameter values. The workaround is a functional builder: a closure receives a builder seeded with the original values and overrides selected fields. A Sourcery stencil template generates the init and builder automatically.
Related posts
- What's new in Swift: September 2026 Edition
Swift.org easyNoviceSwift 6.4 shipped with Swift Build as the default SwiftPM build system, Subprocess 1.0, up to 40x faster WebAssembly bridging via JavaScriptKit, path-based module tracking in debug info (build systems should switch to `-debug-module-path`), and Embedded Swift improvements. Vapor turned ten and released the Vapor 5 beta, a rewrite built on structured concurrency and the new Swift HTTP Server that drops `EventLoopFuture`. Other items include Google Cloud client libraries for Swift, WasmKit 0.4 with a 2x faster interpreter, Swift AWS Lambda Runtime 3.0, and Evolution proposals such as `#if deploymentTargetAtLeast`, same-file memberwise initializer extensions, `resignRemoteID` for distributed actors, and default package settings.
- Swift 6.4 Released
Swift.org mediumAdeptSwift 6.4 makes Swift Build the default backend for SwiftPM, giving consistent builds across Linux, macOS and Windows, adds SBOM generation, and ships Subprocess 1.0 for cross-platform process execution on Swift concurrency. Language changes include async calls in defer blocks, task cancellation shields for guaranteed cleanup, module selectors (`::`) for resolving name conflicts, and a source-level `@diagnose` attribute for controlling warnings. Interop expands with C++20 `std::span` bridging to `Span`, `@c`/`@implementation` for C, and broader Swift/Java async support. JavaScriptKit Wasm bridging is up to 40x faster, Embedded Swift gains existential types, and new ownership-oriented types such as `UniqueArray`, `UniqueBox`, `Ref` and the `Iterable` protocol avoid copies and copy-on-write overhead while staying memory-safe.
- How We Built The Deals Tab in Swift UI
Etsy Code as Craft mediumAdeptEtsy rebuilt its mobile Updates tab as a new Deals tab in SwiftUI inside a modular Tuist module, which made preview builds nearly instant and let the team build modules from mock preview data about two weeks before the APIs were ready. The screen is a SwiftUI List of typed API modules decoded with a Decodable-based APIv3 layer, and nested `Previews` enums supply mock models at every level. To meet the Cyber Week deadline without rewriting legacy Objective-C code, navigation, favoriting and logging are handed back to the main target through custom `@Environment` action handlers. Legacy listing cards are injected as UIViewRepresentable view builders from the UIKit hosting controller.
- Swift 6.3 Released
Swift.org mediumAdeptSwift 6.3 adds a `@c` attribute for exposing Swift functions and enums to C (or implementing C-declared functions in Swift via `@c @implementation`), `Module::name` selectors for disambiguating APIs from different imported modules, and library performance attributes `@specialize`, `@inline(always)` and `@export(implementation)`. SwiftPM gains a preview of the unified Swift Build engine, prebuilt swift-syntax for macro libraries and a `show-traits` command. Swift Testing adds warning-severity issues, test cancellation and image attachments, and DocC gains experimental Markdown output, static HTML content and code block annotations. The release also ships the first official Swift SDK for Android and further Embedded Swift improvements.
- Oxidizing OCaml: Rust-Style Ownership
Jane Street Tech Blog hardMasterJane Street's OCaml extensions add Rust-style ownership through mode axes. A uniqueness axis (unique, exclusive, shared) enables in-place functional updates, type-changing strong updates and safe resource APIs. Borrowing via `&` combines with locality so values can be lent without consuming them. Exclusively mutable fields give mutation without move semantics, and a linearity axis (once vs many) stops closures that capture unique values from being invoked twice, which would otherwise break type safety. Unlike Rust, these modes carry no lifetime variables, so they avoid higher-order polymorphism and don't interfere with type inference.