0

I am new to SwiftUI.... View is a protocol which only contains required stored property called "body". My question is , where modifier methods come from. 'cause "Protocol methods must not have bodies".?

1 Answer 1

2

My question is , where modifier methods come from. 'cause "Protocol methods must not have bodies".?

From extension like in below example:

extension View {
    @ViewBuilder
    public func isHidden(_ hidden: Bool) -> some View {
        if hidden {
            self.hidden()
        }
        else {
            self
        }
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

is this the only way we can add method implementation to protocol ? could you please mention a resource link which I can find more details about this ? it will we help me to learn "how to learn" new things.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.