gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 04:21:23 32 4
gpt4 key购买 nike

嗨,你能帮忙吗 xcode 在第 4 行说:(函数不透明返回类型被推断为“按钮”,它根据自身定义了不透明类型)
感谢您的帮助 <3

Button(action: { self.showingProfile.toggle() }) { - 那一行

struct Profile {

@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() } } }

最佳答案

你想达到这个目标吗?

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

}
}

关于swift - 函数 opaque 返回类型被推断为 ... 它根据自身定义了 opaque 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59229011/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com