The error I am getting is: Result values in '? :' expression have mismatching types 'some View' (result of 'Self.redacted(reason:)') and 'some View' (result of 'Self.unredacted()')
But aren't some View and some View the same thing.
This method is part of a view:
and then used on the view in ContentView like this:
Even if I use an if statement this error still occurs: Function declares an opaque return type, but the return statements in its body do not have matching underlying types
How can I return either of two modifiers that both return some View from a method that returns some View?
But aren't some View and some View the same thing.
This method is part of a view:
Code Block Swift func redacted(when active: Bool) -> some View { active ? redacted(reason: .placeholder) : unredacted() }
and then used on the view in ContentView like this:
Code Block Swift TestView() .redacted(when: isActive)
Even if I use an if statement this error still occurs: Function declares an opaque return type, but the return statements in its body do not have matching underlying types
How can I return either of two modifiers that both return some View from a method that returns some View?
NO. some View means some specific type conforming to View. some View here and some View there may or may not be the same type.But aren't some View and some View the same thing.
One way is using AnyView.How can I return either of two modifiers that both return some View from a method that returns some View?
Code Block func redacted(when active: Bool) -> some View { return active ? AnyView(redacted(reason: .placeholder)) : AnyView(unredacted()) }