“类声明中的预期标识符”错误

时间:2019-12-05 23:06:56

标签: swift

我的代码有问题:

Appel constructeur !
0x55c91bff3e70
Appel constructeur !
0x55c91bff3e71
2
0x55c91bff3e70
0x55c91bff3e71
Appel destructeur !
Appel destructeur !

Xcode在第2行上说:

  

“类声明中的预期标识符”

2 个答案:

答案 0 :(得分:0)

假设您在结构中实现了类似showingProfile: Bool的内容,则应使用self关键字(而不是class)来调用它:

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

答案 1 :(得分:0)

使用此self.showingProfile.toggle()代替 class.showingProfile.toggle()