State - free lesson 11 war game

Hi, I am coding along on lesson 11 about state properties and we are building the war game.
on the minute 6:50 of the tutorial we are coding the @State before each var.
In my case I get a red alert by each var stating “property wrappers are not yet supported”
I was googling it but really couldn’t find anything on it.

Thank you

Ewa

struct ContentView: View {
var body: some View {

@State var playerCard = "card5" here comes error: property wrappers are not yet supported for each var
@State    var cpuCard = "card9"
@State    var playerScore = 0
@State    var cpuScore = 0

Hi Ewa,

What Version of Xcode are you using and what version of MacOS do you have installed.

The SwiftUI framework is only supported on Macs that are running at least Catalina and also using Xcode version 11 or later.

From an article on Paul Hudsons hackingwithSwift.com website he says:

  • SwiftUI runs on iOS 13, macOS 10.15, tvOS 13, and watchOS 6, or any future later versions of those platforms.

Thank you Chris for you fast reply!
My Xcode version is 12.3 i updated recetly and it took so much time
i ma on mcbook air MacOs BigSur version 11.1

OK can you share your code that you are having trouble with.

1 Like

//
// ContentView.swift
// wargame
//
// Created by Ewa Boer on 18/01/2021.
//

import SwiftUI

struct ContentView: View {
var body: some View {

@State var playerCard = "card5" //here comes the error: property wrappers are not yet supported on local properties, and it appears by each @State var

@State var cpuCard = "card9"
@State var playerScore = 0
@State var cpuScore = 0
    
    ZStack {
        Image("background")
            .ignoresSafeArea()
        VStack {
            
            Spacer()
            
            Image("logo")
            //////////
            Spacer()
            
            HStack {
                Spacer()
                Image(playerCard)
                Spacer()
                Image(cpuCard)
                Spacer()
                
            }
            
            Spacer()
           ///////////////////
            Button(action: {
                
                playerCard = "card1"
                cpuCard = "card12"
                
                //update the cards
                layerScore += 1
                cpuScore += 1
                //update the score
            }, label: {
                Image("dealbutton")
            })
           
                
            Spacer()
            
            HStack {
                Spacer()
                VStack {
                    Text(/*@START_MENU_TOKEN@*/"Player"/*@END_MENU_TOKEN@*/)
                        .font(.headline)
                        .padding(.bottom, 20.0)
                    Text(String(playerScore))
                        .font(/*@START_MENU_TOKEN@*/.largeTitle/*@END_MENU_TOKEN@*/)
                }
                
                Spacer()
                
                VStack {
                    Text(/*@START_MENU_TOKEN@*/"CPU"/*@END_MENU_TOKEN@*/)
                        .font(/*@START_MENU_TOKEN@*/.headline/*@END_MENU_TOKEN@*/)
                        .padding(.bottom, 20.0)
                    Text(String(
                    cpuScore))
                        .font(/*@START_MENU_TOKEN@*/.largeTitle/*@END_MENU_TOKEN@*/)
                }
                
                Spacer()
            }
            
            .foregroundColor(/*@START_MENU_TOKEN@*/.white/*@END_MENU_TOKEN@*/)
            
            Spacer()
           
        }
    }
    
}

}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()

}

}

Move your State declarations up between
struct ContentView: View {

and

var body: some View {

like this:

struct ContentView: View {
    @State var playerCard = "card5" 
    @State var cpuCard = "card9"
    @State var playerScore = 0
    @State var cpuScore = 0

    var body: some View {

        ZStack {
            Image("background")
                .ignoresSafeArea()
           // The rest of your code below this
1 Like