1

I am doing this:

extension View {
    func isHidden(_ hidden: Bool) -> AnyView {
        AnyView(hidden ? self.hidden() : self)
    }
}

I would prefer something like this:

extension View {
    func isHidden(_ hidden: Bool) -> some View {
        return hidden ? self.hidden() : self
    }
}

Is this possible and/or am I worrying needlessly? thx

1 Answer 1

2

Yes, it is possible. Here it is

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.