'Function opaque return type was inferred as ... which defines the opaque type in terms of itself

Xcode gives the error:

Function opaque return type was inferred as 'Button', which defines the opaque type in terms of itself

on the line below:

@State var showingProfile = false // Could be also Binding or else

var profileButton: some View {
Button(action: { self.showingProfile.toggle() }) { // <- Error on this line
    Image(systemName: "person.crop.circle")
        .imageScale(.large)
        .accessibility(label: Text("User Profile"))
        .navigationBarItems(trailing: self.profileButton)
         .padding() } } }


Solution 1:[1]

do you want to achieve this?

struct ProfileButton: View {

    @State var showingProfile = false // Could be also Binding or else

    var body: some View {

        Button(action: {
            self.showingProfile.toggle()
        }) {
            Text("blubb")
            Image(systemName: "person.crop.circle")
                .imageScale(.large)
                .accessibility(label: Text("User Profile"))
                .padding()
        }
    }
}

struct ContentView: View {

    let profileButton = ProfileButton(showingProfile: true)

    var body: some View {
        NavigationView {
            Text("aah")
            .navigationBarTitle("Test")
            .navigationBarItems(trailing: Image(systemName: "person.crop.circle"))
        }

    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Chris