Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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() } } }
like image 920
kiwi Avatar asked Nov 07 '22 11:11

kiwi


1 Answers

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"))
        }

    }
}
like image 105
Chris Avatar answered Nov 15 '22 05:11

Chris