@Binding cannot be used as an attribute

Viewed 746

Im following a tutorial about SwiftUI and I am hitting a problem

the following is my effort to bind a boolean from one struct view to another

import SwiftUI
import Foundation
struct BindingTwo: View {

    let episod = Episode(name: "MacBreak Weekly", track: "WWDC 2019")
    @State private var isPlaying = false
    var body: some View {

        VStack{

            Text(self.episod.name).font(.title).foregroundColor(self.isPlaying ? Color.green : Color.black)

        Text(self.episod.track).foregroundColor(.secondary)

            PlayButton(isPlaying: isPlaying)
        }

    }
}

struct PlayButton : View {
    *@Binding var isPlaying : Bool* this line is generating the error
    var body : some View {
        Button(action: {self.isPlaying.toggle()}){
            Text("Play")
        }
        .foregroundColor(Color.white)
        .background(Color.black)
        .padding(12)
    }
}

but the @Binding line keeps getting the following error: "Struct 'Binding' cannot be used as an attribute" as far as I can tell this is the same as the tutorial, I cant figure out what it is I have missed, anybody see this before?

3 Answers

Though I didn't get the error you mention. But your code is working perfectly, just change this:

PlayButton(isPlaying: self.$isPlaying)

I'm not seeing this particular error. Are you using MacOS Catalina version 10.15+? SwiftUI only works in Catalina.

Just uninstalled Xcode and reinstalled, the @Binding error has gone, though my simulator and canvas are noticeably slower, I think there may just be intermittent problems around new releases, in time perhaps the normal speed will return

Related