Swift Macros have brought in a new wave of possibilities. The aim of this project is to curate a list of community-created Macros and associated learning resources.
Learning Resources 📚
- Swift AST Explorer
Dive into Swift Macros with these WWDC sessions:
- Write Swift Macros: An introductory session on Macros, their roles, and workings with a basic example.
- Expand Swift Macros: A deeper exploration into crafting your Macros and testing their functionality.
Other Apple Resources:
- Macros: The Official Step-by-Step Guide to Using Macros for Compile-Time Code Generation in Swift.
- Example Swift Macros: Check out real-world examples from Apple, like
- Swift Macros by SwiftLee
- Antoine goes over the introduction of what Macros are and how you can build your own one with an example.
- How to Create Swift Macros in Xcode 15
- Francesco goes over creating your first macro with testing and some interesting tidbits.
- Exploring Swift Macros
- Sergey goes over creating a macro for a memberwise initaliser step by step with tests and convenience methods for SwiftSyntax
- Automating RawRepresentable Conformance with Swift Macros
- Nikita goes over creating a macro for automating the String RawRepresentable conformance.
- EnvironmentValues & EnvironmentValue: Bypass boilerplate code and swiftly support new SwiftUI Environment Keys and Values.
- SFSymbols Macro: A Swift Macro for “type-safe” SF Symbols.
- Coding Keys: Effortlessly generate CodingKeys for converting
- Coding Keys: A Swift Macro for automating CodingKeys creation in Codable structs. Supports custom string mappings for properties.
- Builder pattern: Apply the Builder Pattern with ease by generating a
Builderhelper class, mimicking stored properties of the associated struct.
- EnhancedMirror: An experimental Mirror alternative that utilizes Swift Macros for static reflection.
- Power Assert: Adds assertions that can automatically produce information about the values being evaluated, and present it in an easily digestible form.
- Spyable: A Swift macro that simplifies and automates the process of creating spies for testing. Using the
@Spyableannotation on a protocol, the macro generates a spy class that implements the same interface as the protocol and keeps track of interactions with its methods and properties.
- SwiftRequest: SwiftRequest is a lightweight, type-safe HTTP client for Swift, streamlining the construction and execution of HTTP request build on top of Macros.
- ExtractCaseValue: A Swift macro that extracts associated values from enum cases.
- MacroKit: A collection of macros including:
@PublicInit: Generate public memberwise init
@GenerateMock: Create a mock object for testing from a protocol
CaseIterablebut for available keypaths on a type
CaseIterablebut for available static members on a type
- More to come…
- InitMacro: A Swift Macro implementation that generates initializers for classes and structs with support for default values, wildcards and access control.
- AssociatedObject: A Swift Macro for adding stored properties in Extension to classes defined in external modules, etc.
(This is implemented by wrapping
- UtilityType: UtilityType is an innovative library designed to realize TypeScript’s UtilityTypes in Swift. See more details: https://www.typescriptlang.org/docs/handbook/utility-types.html
@Required: Constructs a type with all properties set to optional(
@Partial) or require(
@Required). This utility will return a type that represents all subsets of a given type.
@Omit: Constructs a type by picking(
@Pick) or removing(
@Omit) the set of specific properties keys (only string literal) from attached Type.
@Extract: Constructs a type by excluding(
@Exclude) or extracting(
@Extract) from enum all cases.
@Parameters: Constructs a tuple type from the types used in the parameters of a function type.
@ReturnType: Constructs a type consisting of the return type of function.
- Reuse Identifier: A Reuse Identifier Macro that is useful in generation of a reuse id for your UICollectionViewCells and UITableViewCells
Mobile App Development Best Practices – 03.10
iOS MetaCodable – Supercharge Swift’s Codable implementations with macros meta-programming How to build a Tuist plugin and publish it using...
How to make and use BOM (Bill of Materials) dependencies in Android projects
By using a BOM dependency, you can avoid specifying the versions of each individual library in your app, and let...
Telegram turns 10 years old and revenues stagnate
Telegram seems to want to grow not only through messaging but also through communities, which pretty much means it wants...
MetaCodable – Supercharge Swift’s Codable implementations with macros meta-programming
Supercharge Swift‘s Codable implementations with macros. Overview MetaCodable framework exposes custom macros which can be used to generate dynamic Codable implementations. The core of the framework...
How to get started with Swift Concurrency 🧵 (Beginner Tutorial)
Swift has built-in support for writing asynchronous and parallel code in a structured way. Asynchronous code can be suspended and resumed later,...
Mobile App Development Best Practices – 02.10
Data.ai has summarized the interim results of the year – and once again we have a record. Annual consumer spending...