I am studying SwiftUI. So I’m creating climate app with @state toggling. I created button view however I am battling passing isDark.toggle
operate as a parameter for my button view. I get Escaping autoclosure captures 'inout' parameter 'self'
I’ve my button view
struct WeatherButton: View {
var textual content: String
var motion: () -> Void
init(textual content: String, motion: @escaping () -> Void) {
self.textual content = textual content
self.motion = motion
}
var physique: some View {
Button(motion: {
motion()
}, label: {
Textual content(textual content)
.body(width: 280, top: 50)
.background(.white)
.font(.system(dimension: 20, weight: .daring))
.cornerRadius(10)
})
}
}
and the way i exploit it
@State non-public var isDark = false
...
WeatherButton(textual content: "Theme toggle would not work",
motion: isDark.toggle)