Can I add a generic ViewModifier to the Library?

I have a ViewModifier that I use by extending View as such:
Code Block
extension View {
    func asCard() -> some View {
        self.modifier(CardViewModifier())
    }
}

I tried adding it to the Library as such:
Code Block
    @LibraryContentBuilder
    func modifiers(base: View) -> [LibraryItem] {
        LibraryItem(base.asCard)
    }

But that produces the following error message:
Protocol 'View' can only be used as a generic constraint because it has Self or associated type requirements

I also tried using Any but that didn't work either.
Accepted Answer
Yup, you get that error because what that signature is expecting is a concrete view implementation, not a protocol. Since your modifier is applicable to any type that conforms to View you can provide literally any type in that signature, as long as it conforms to View, just pick one of your favorites: Text, Button, VStack, MyCustomView.

The following should work:

Code Block
@LibraryContentBuilder   
func modifiers(base: AnyView) -> [LibraryItem] {
LibraryItem(base.asCard)   
}


Can I add a generic ViewModifier to the Library?
 
 
Q