A Swift macro that brings SwiftUI-style customization to your own reusable view components — without boilerplate.
Inspired by how native SwiftUI views like Text and TextField separate required data from optional styling, @ViewConfigurable makes your custom views easier to use and extend.
With @ViewConfigurable, you can:
- Create a
ViewConfigurationstruct inside your view - Use a single
viewConfigproperty to apply all styling - Automatically generate fluent-style setters like
.font(_:),.backgroundColor(_:),.onScroll(_:), etc. - Keep your initializers small and clean
- Avoid cluttering your
Viewwith dozens of optional parameters
Add the package to your Package.swift:
.package(
url: "https://github.com/grindrllc/view-configurable",
from: "0.1.1"
)Then add "ViewConfigurable" to your target dependencies:
.target(
name: "YourApp",
dependencies: [
.product(name: "ViewConfigurable", package: "view-configurable")
]
)Requires Swift 5.9+ and Xcode 15+
import SwiftUI
import ViewConfigurable
@ViewConfigurable
public struct GrindrButton: View {
private let title: String
private let onAction: () -> Void
private var viewConfig = ViewConfiguration()
struct ViewConfiguration {
var titleColor: Color = .black
var backgroundColor: Color = .yellow
var font: Font = .body
}
public init(title: String, onAction: @escaping () -> Void) {
self.title = title
self.onAction = onAction
}
public var body: some View {
Button(action: onAction) {
Text(title)
.font(viewConfig.font)
.foregroundColor(viewConfig.titleColor)
}
.background(viewConfig.backgroundColor)
}
}GrindrButton(title: "Tap Me", onAction: {})
.titleColor(.blue)
.backgroundColor(.purple)
.font(.callout)🎉 You get SwiftUI-style customizability without inflating your initializer.
As your components grow, constructor-based configuration becomes painful to maintain and use. @ViewConfigurable helps you:
- Keep your views clean and maintainable
- Reduce initializer bloat
- Encourage consistent, idiomatic customization
It’s like giving your own views the ergonomics of Text, TextField, or Button.
If your view is missing a ViewConfiguration struct or viewConfig property, the macro will emit a warning with fix-it suggestions.
MIT License © 2025 Grindr LLC.
See LICENSE for details.
Built with 💛 by the iOS team at Grindr
Feel free to open an issue or submit a PR. We’re excited to see how others use @ViewConfigurable in their SwiftUI components!