I was trying to create a logger instance for each of my projects, without manually having to create the file for each of them, similar to how the bundle accessors are defined, something along the lines of:
import OSLog
extension Logger {
static let logger = Logger(subsystem: "io.tuist.subsystem", category: "io.tuist.targetName")
}
However, currently I am unable to do this natively. One of the solutions would be to create a fake resource file, specifically recognisable for a logger resource synthesizer, or I could create a plugin or target script that runs before I build the project. None of those solutions really appeal to me.
I would like to be able to leverage SwiftGen to create code in the Derived
folder, similar to how resources are synthesised and the bundle accessors are created. I would think of this as a general Synthesizer
, something that can generate code for us.
public protocol Synthesizer {}
public struct ResourceSynthesizer: Synthesizer {}
public struct StaticSynthesizer: Synthesizer {}
The protocol Synthesizer
could be something we would like to have anyways, as in the future we might be able to use it to support different code generators.
The existing ResourceSynthesizer
should only be minimally affected, depending on how elaborate the Synthesizer
protocol is made.
Then at the call site, I would opt to upgrade the resourceSynthesizer
parameter to just being a generic Synthesizer
parameter.
Project(
name: "Generate Me",
synthesizers: [
ResourceSynthesizer(/* ... */),
StaticSynthesizer(/* ... */)
]
)
We should be able to support the helper functions like we do right now too.
extension Synthesizer where Self == ResourceSynthesizer {
public static func resource(_ synthesizer: Self) -> Synthesizer {}
}
extension Synthesizer where Self == StaticSynthesizer {
public static func `static`(_ synthesizer: Self) -> Synthesizer {}
}
Project(
name: "Generate Me",
synthesizers: [
.resource(.assets()),
.resource(.custom(name: "Lotties", parser: .json, extensions: ["lottie"])),
.static(.bundleAccessors),
.static(.custom(name: "Logger"))
]
)
13.4.1
3.20.0
14.3.1
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too