I have this code in one of my views:
struct TextFieldClearButton: ViewModifier {
@Binding var text: String
func body(content: Content) -> some View {
HStack {
content
if !text.isEmpty {
Button(
action: { self.text = "" },
label: {
Image(systemName: "delete.left")
.foregroundColor(Color(UIColor.opaqueSeparator))
}
)
}
}
}
}
I get two errors:
Type 'TextFieldClearButton' does not conform to protocol 'ViewModifier'Static method 'buildBlock' requires that 'Content' conform to 'View'How can I get rid of these errors and make this modifier compile?

It looks like I can't use ViewModifier at all. Adding super simple case errors out too??:

You likely have a struct/class in your project named Content
If you have Xcode's standard dark theme the "mint"/"greenish" means it is "Project" defined.

When you are using Apple's definition it is pinkish/purple like ViewModifier, View, and String in your screenshot.

Search for struct Content, class Content, enum Content, etc. In your project, You will find the duplicate and then just change the name of the duplicate.
It could also be a generic <Content: SomeProtocol> or <Content> or typealias Content
You can confirm the duplicate by being more specific

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With