Search code examples
swiftxcodeswiftuiviewmodifier

Swift Compiler Error: "Type 'Watermark' does not conform to protocol 'ViewModifier'"


I want to add a ViewModifier, as explained in the following tutorial by Paul Hudson (https://www.hackingwithswift.com/books/ios-swiftui/custom-modifiers). My ViewModifier is:

import SwiftUI

struct Watermark: ViewModifier {
    var text: String

    func body(content: Content) -> some View {
        ZStack(alignment: .bottomTrailing) {
            content
            Text(text)
                .font(.caption)
                .foregroundColor(.white)
                .padding(5)
                .background(Color.black)
        }
    }
}

extension View {
    func watermarked(with text: String) -> some View {
        self.modifier(Watermark(text: text))
    }
}

But I get the following Errors:

enter image description here

I tried to reproduce this in another project, but there it just works as expected. I tried already cleaning the build folder, remove the derived data, restart Xcode, restart the Mac.

Any ideas on how to solve the issue?


Solution

  • I experienced this error before and as what @Asperi said it is naming conflict issue. There may have another entity also named Content in the project.

    And images for reference: