Replies: 1 comment 5 replies
-
Hi @Jeehut, I'm not 100% certain, but I believe the macro syntax you have theorized can't actually work with macros today. Another wrinkle to take into account is that adding swift-syntax to a package incurs a 30 second compilation penalty, which is pretty significant for a library that currently compiles in less than 2 seconds. That means it would probably have to vended in a separate "DependenciesMacros" library, or the macro would have to be written without using swift-syntax, which can be difficult. We're certainly open to reducing the boilerplate for registering a dependency, but at the end of the day it is also quite insignificant compared to the code that is written everyday. If you end up experimenting with what's possible please do share in this discussion. |
Beta Was this translation helpful? Give feedback.
-
I just registered a custom dependency by writing the following boilerplate code in my existing
APIClient.swift
file:While this is kinda manageable, I tend to define multiple dependencies per project and always need to look up and copy & paste the syntax on how to define these as I can't really memorize the type names
DependencyKey
andDependencyValues
. And I have a feeling that the above boilerplate code (especially the extension) could be generated by a macro. I would imagine something like this:I'm not sure if extending types or creating new types is supported by macros (yet), but any improvements that make the registration of custom dependencies easier and less type- and lookup-intensive would be appreciated!
The suggested syntax with the
values
could be replaced by a convention-based mechanism, automatically detectinglive
,test
, or other static properties of typeSelf
within the dependency type. When novalues
are specified, onlylive
could be automatically detected if the type has an initializer without parameters. Just a few first thoughts to get started.Beta Was this translation helpful? Give feedback.
All reactions