Currently learning Swift (in Xcode specifically), and this seemingly very simple operation isn’t working. I’m not sure what I’m doing wrong (simplified code):
var taps: Int = 0
var body: some View {
Button(action: { taps += 1 }) { /* ... */ } // Left side of mutating operator isn't mutable: 'self' is immutable
}
I’ve tried a few variations of this, including taps = taps + 1
, which didn’t work for the same reason. My understanding is that in Swift, var
is mutable, so what’s wrong here?
2