• Stars
    star
    2,120
  • Rank 21,762 (Top 0.5 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 1 year ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A curated list of awesome Swift Macros

Swift Macros ๐Ÿš€



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.

A lot of use-cases my Sourcery covered before can now be implemented by Swift Macros.






Learning Resources ๐Ÿ“š

Tools

Apple:

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 @AddCompletionHandler and @AddAsync.

Community Blogs


Macros ๐Ÿ’ป

SwiftUI

Models

  • Coding Keys: Effortlessly generate CodingKeys for converting snake_case to lowerCamelCase.
  • Coding Keys: A Swift Macro for automating CodingKeys creation in Codable structs. Supports custom string mappings for properties.
  • Coding Keys: Swift macros generating customizable CodingKeys.
  • Builder pattern: Apply the Builder Pattern with ease by generating a Builder helper class, mimicking stored properties of the associated struct.
  • Struct Builder Macro: An attached macro that produces a peer struct which implements the builder pattern. This allows the creation of the struct with minimal effort using default values.
  • EnhancedMirror: An experimental Mirror alternative that utilizes Swift Macros for static reflection.
  • MetaCodable: Generates Codable implementation with following features:
    • Allows custom CodingKey value declaration per variable, instead of requiring you to write for all fields.
    • Allows to create flattened model for nested CodingKey values.
    • Allows to create composition of multiple Codable types.
    • Allows to provide default value in case of decoding failures.
    • Generates member-wise initializer considering the default values.
    • Allows to create custom decoding/encoding strategies.
  • Sealed: Parsing easily Sealed Class JSON Model on Server. (ex. kotlin server)

Testing

  • 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 @Spyable annotation 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.

Networking

  • SwiftRequest: SwiftRequest is a lightweight, type-safe HTTP client for Swift, streamlining the construction and execution of HTTP request build on top of Macros.
  • Papyrus: A type-safe, protocol based HTTP client - turn your APIs into Swift protocols. Includes first-class testing support with out of the box mocking.

Enums

  • ExtractCaseValue: A Swift macro that extracts associated values from enum cases.

Misc

  • MacroKit: A collection of macros including:
    • @PublicInit: Generate public memberwise init
    • @GenerateMock: Create a mock object for testing from a protocol
    • @KeyPathIterable: Like CaseIterable but for available keypaths on a type
    • @StaticMemberIterable: Like CaseIterable but 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 objc_getAssociatedObject/objc_setAssociatedObject.)
  • AssociatedObjectMacro: A Swift Macro for convenient declaration of variables in class extensions.
  • AliasMacro: A Swift Macro for defining aliases for types, functions, or variables.
  • 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
    • @Partial,@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.
    • @Pick,@Omit: Constructs a type by picking(@Pick) or removing(@Omit) the set of specific properties keys (only string literal) from attached Type.
    • @Exclude,@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
  • SwiftMacros collection: A practical collection of Swift Macros that help code correctly and smartly.
  • ModifiedCopyMacro: A Swift macro for making inline copies of a struct by modifying a property.
  • DictionaryLiteralShorthandMacro: A Swfit macro for creating dictionary literals with keys as "string representations of corresponding variable names".
  • TemporaryVariable: TemporaryVariable provide a macro #info {...}. It capture most function calls and assign them to temporary variables.
  • Localizable: Localizable A macro that produces variables and methods, for your localization files. From the enumeration keys.

Take part in this exciting evolution in Swift. Your contributions are most welcome!

More Repositories

1

Sourcery

Meta-programming for Swift, stop writing boilerplate code.
Swift
7,677
star
2

LifetimeTracker

Find retain cycles / memory leaks sooner.
Swift
3,144
star
3

Playgrounds

Better playgrounds that work both for Objective-C and Swift
Objective-C
2,633
star
4

Inject

Hot Reloading for Swift applications!
Swift
2,127
star
5

Bootstrap

iOS project bootstrap aimed at high quality coding.
Objective-C
2,047
star
6

LineDrawing

Beatiful and fast smooth line drawing algorithm for iOS - as seen in Foldify.
Objective-C
1,288
star
7

Difference

Simple way to identify what is different between 2 instances of any type. Must have for TDD.
Swift
1,217
star
8

PropertyMapper

Property mapping for Objective-C iOS apps.
Objective-C
1,124
star
9

KZFileWatchers

A micro-framework for observing file changes, both local and remote. Helpful in building developer tools.
Swift
1,078
star
10

LinkedConsole

Clickable links in your Xcode console, so you never wonder which class logged the message.
Swift
931
star
11

Traits

Modify your native iOS app in real time.
Swift
904
star
12

IconOverlaying

Build informations on top of your app icon.
Shell
650
star
13

crafter

Crafter - Xcode project configuration CLI made easy.
Ruby
547
star
14

Strongify

Strongify is a 1-file ยตframework providing a nicer API for avoiding weak-strong dance.
Swift
444
star
15

KZNodes

Have you ever wonder how you could make Origami like editor in 1h ?
Objective-C
336
star
16

SFObservers

NSNotificationCenter and KVO auto removal of observers.
Objective-C
307
star
17

AutomaticSettings

Data driven settings UI generation.
Swift
302
star
18

CCNode-SFGestureRecognizers

Adding UIGestureRecognizers to cocos2d, painless.
Objective-C
202
star
19

DetailsMatter

Objective-C
199
star
20

Pinch-to-reveal

Pinch to reveal animation transition built with Layer masking, as seen in boeing app for iPad.
Objective-C
192
star
21

ViewModelOwners

Protocols that help make your MVVM setup more consistent
Swift
143
star
22

KZAsserts

Asserts on roids, test all your assumptions with ease.
Objective-C
100
star
23

OhSnap

Reproduce bugs your user saw by capturing and replaying data snapshots with ease.
Swift
89
star
24

Versionable

Migration for `Codable` objects.
Swift
83
star
25

SFContainerViewController

UIViewControllers containment predating Apple implementation. Works in both 4.x and 5.x iOS, no memory or hierarchy issues.
Objective-C
82
star
26

Swift-Observable

Native KVO like behaviour build in Swift.
Swift
64
star
27

BehavioursExample

Objective-C
58
star
28

SourceryWorkshops

Swift
45
star
29

Learn-iOS-GameDev-Level-0

Teeter clone accompanying tutorial at http://merowing.info/2013/04/learn-ios-game-dev-level-0/
Objective-C
24
star
30

XibReferencing

Simple category and sample showing how you can reference one Xib view from another
Objective-C
20
star
31

KZImageSplitView

Objective-C
17
star
32

NSObject-SFExecuteOnDealloc

A simple category on NSObject that allows you to execute block when object is deallocated
Objective-C
17
star
33

jenkins_jobs_to_statusboard

Ruby script that generates html table for embedding in StatusBoard by Panic http://panic.com/statusboard/
Ruby
15
star
34

SourceryPro-Feedback

Repository for discussing https://merowing.info/sourcery-pro/
12
star
35

krzysztofzablocki

2
star
36

krzysztofzablocki.github.io

Blog
HTML
2
star
37

starter-hugo-academic

Jupyter Notebook
1
star