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
Either of these solutions dont work for me?
@jaijordan
Welcome to the Code Crew community.
It might be best to create a new post and ask a specific question and provide the code for the View in which you are using the State variable so we can see the context in which it is being used.
Paste your code in as text, rather than providing a screenshot, and place 3 back-ticks ``` on the line above your code and 3 back-ticks ``` on the line below your code so that it is formatted nicely. This also makes it easier for anyone assisting as they can copy the code and carry out some testing rather than having to type the code in from an image.