Skip to content

A WIP Swift macro to generate concrete protocol witnesses from a protocol. These are ready to be injected with properties and behaviour (infusing overriding constants) to create production implementations, testing variants, SwiftUI Preview variations, preproduction and more.

Notifications You must be signed in to change notification settings

adammcarter/ProtocolWitnessable

Repository files navigation

example workflow

Known issues

Duplicate function names

Problem

Functions with the same opening function name but distinct signatures via different parameter names will conflict.

For example, the two functions below:

func data(for request: URLRequest) async throws -> (Data, URLResponse)
func data(from url: URL) async throws -> (Data, URLResponse)

Will be expanded to:

var _data: (URLRequest) async throws -> (Data, URLResponse)
var _data: (URL) async throws -> (Data, URLResponse)

which will conflict because the two property names _data are the same and will throw a compiler error:

❌ Invalid redeclaration of '_data'

Workaround

Distinguish the function's opening names explicitly, eg, the above example can be turned in to:

func dataForRequest(_ request: URLRequest) async throws -> (Data, URLResponse)
func dataFromURL(_ url: URL) async throws -> (Data, URLResponse)

Which is expanded to:

var _dataForRequest: (URLRequest) async throws -> (Data, URLResponse)
var _dataFromURL: (URL) async throws -> (Data, URLResponse)

And leaves a happy compiler 🤖

About

A WIP Swift macro to generate concrete protocol witnesses from a protocol. These are ready to be injected with properties and behaviour (infusing overriding constants) to create production implementations, testing variants, SwiftUI Preview variations, preproduction and more.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages