Lesson 11 (State Properties) - have to add self property

In lesson 11 for the @State properties, when I am referencing them in the Button action section, an error gets thrown up that I have to explicitly reference the self property.

This occurs with both the numerical and card variables. So for example, rather than writing:

playerScore ±= 1

I have to use:

self.playerScore += 1

What is the reason for this? I am initiating the State variable in the correct section of the content view structure.

What version of Xcode are you using? Prior to Xcode 12 and Swift 5.3, you had to use self in those cases but you no longer need to do so.

1 Like

Ah thank you - I’m using v11.3 - much appreciated!

@dedgcumbe

Welcome to the community!! Next time please ask your question in the appropriate category “App Development” not Community

1 Like