函数opaque返回类型推断为...,它根据自身定义了opaque类型

时间:2019-12-07 18:24:04

标签: swift xcode swift4 swiftui

您好,请您帮忙xcode在第4行上说:(函数不透明返回类型被推断为'Button',它根据自身定义了不透明类型) 感谢您帮助<3

按钮(操作:{self.showingProfile.toggle()}){-该行

  

结构配置文件{

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

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

1 个答案:

答案 0 :(得分:1)

您要实现这一目标吗?

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

    }
}