If a protocol, represented in a generic placeholder (ModifiedCircle.Modifier, here) has static members, and you want to use them in an extension to another type, is there any better option than passing along the metatype?
SwiftUI’s modifier-heavy approach is the biggest obvious use case for this, but it’s not at all specific to SwiftUI.
struct ModifiedCircle<Modifier: Circle.Modifier>: View {
var body: some View {
Circle().modified(Modifier.self) // Can you improve this?
}
}
extension Circle {
protocol Modifier {
associatedtype Modified: View
static func modify(_ circle: Circle) -> Modified
}
func modified<Modifier: Circle.Modifier>(_: Modifier.Type) -> some View {
Modifier.modify(self)
}
}