A Kotlin Style .copy Function for Swift Structs - Shopify
Sep 2, 2021

Summary
This post introduces a solution for implementing a Kotlin-like `.copy()` function in Swift structs to facilitate immutable object patterns. It details the challenges with Swift's default initializers and optional properties, proposes a builder pattern as an alternative, and highlights the use of Sourcery for automating the generation of initializers and builders, thereby reducing boilerplate code for developers working with immutable state in the iOS codebase.
More from the Shopify Mobile Hybrid Architecture trail
- Mobile Bridge: Making WebViews Feel Native (2025) - Shopify
- Migrating our Largest Mobile App to React Native - Shopify
- Implementing Server-Driven UI Architecture on the Shop App - Shopify
- Remote rendering: Shopify’s take on extensible UI - Shopify
- Shipit! Presents: How We Write React Native Apps - Shopify