Swift ';类声明中需要的标识符';错误
我对代码有问题:Swift ';类声明中需要的标识符';错误,swift,Swift,我对代码有问题: var profileButton:一些视图{ 按钮(操作:{class.showingProfile.toggle()}){ 图像(系统名称:“person.crop.circle”) .imageScale(.large) .可访问性(标签:文本(“用户配置文件”)) .padding() }} Xcode在第2行说: “类声明中应包含标识符” 假设您在结构中实现了类似于showingProfile:Bool的东西,您应该通过self关键字(而不是class)调用它: 使
var profileButton:一些视图{
按钮(操作:{class.showingProfile.toggle()}){
图像(系统名称:“person.crop.circle”)
.imageScale(.large)
.可访问性(标签:文本(“用户配置文件”))
.padding()
}}
Xcode在第2行说:
“类声明中应包含标识符”
假设您在结构中实现了类似于
showingProfile:Bool
的东西,您应该通过self
关键字(而不是class
)调用它:
使用此
self.showingProfile.toggle()
而不是
class.showingProfile.toggle()
Xcode说@State var showingProfile=false//顶级代码按钮中还不支持属性包装(操作:{self.showingProfile.toggle()}){//使用未解析的标识符“self”做什么?感谢您的帮助我假设您知道应该将其放入结构中。
@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"))
.padding()
}}