Source: https://developer.apple.com/documentation/swiftui/managing-user-interface-state
This example shows how @State is used.
struct PlayerView: View {
@State private var isPlaying: Bool = false
var body: some View {
Button(action: {
self.isPlaying.toggle()
}) {
Image(systemName: isPlaying ? "pause.circle" : "play.circle")
}
}
}
You need to put the view as root view and run the APP
let contentView = PlayerView().environment(\.managedObjectContext, context)