SwiftUI; Can I use abstraction here?

I'm building a swiftUI app. On smaller iOS devices, I want to show a button that will open a webView. on larger devices, I want to show the webView in the current hierarchy.

The following code:
Code Block
    func showNotesView() -> some View {
        if horizontalSizeClass == .compact {
            return NavigationLink(destination: webView) {
                Text("Episode Notes")
            }
        }
            return webView
    }

generates a compile error at line1
Function declares an opaque return type, but the return statements in its body do not have matching underlying types
  • 1. Return statement has underlying type 'NavigationLink<Text, some View>'

  • 2. Return statement has underlying type 'some View'

Try wrapping each of the return statements in AnyView():
Code Block Swift
return AnyView(NavigationLink(...))

and
Code Block Swift
return AnyView(webView)

SwiftUI; Can I use abstraction here?
 
 
Q