Automatically generate decorator classes for Swift protocols using macros. Just add @Decoratable to your protocol — the macro will create a ready-to-use decorator class!
- 🚀 Auto-generated decorators for Swift protocols
- 🔒 Full access control support (public, internal, fileprivate, private)
- 📦 2-minute integration via Swift Package Manager
- Add the package to your
Package.swift:
dependencies: [
.package(
url: "https://github.com/Kristalev/DecoratableMacro.git",
from: "1.0.0"
)
]- Add to your target:
.target(
name: "YourTarget",
dependencies: [
.product(name: "DecoratableMacro", package: "DecoratableMacro")
]
)- Annotate your protocol with @Decoratable:
import DecoratableMacro
@Decoratable
protocol Router {
func push(viewController: UIViewController)
}- The macro generates:
class RouterDecorator: Router {
private var decoree: any Router
init(_ decoree: any Router) {
self.decoree = decoree
}
func push(viewController: UIViewController) {
decoree.push(viewController: viewController)
}
}- Works only with protocols (not classes/structs)
- Doesn't support generic protocols
- Not supported method modifier compatibility (async/throws)
This project is MIT licensed. See LICENSE for details.
⭐ If you find this useful, please consider starring the repo! 🐞 Bugs & feature requests: Issues