I'm getting the same with the following code for a simple calculator app:
struct ContentView: View {
//Local variables and constants
@State var operatorChain: [String] = []
@State var oprandChain: [Double] = []
@State var operand: Double = 0.0
@State var resultText: String = ""
@State var numericalResult: Double = 0.0
let defaultText: String = "0"
var body: some View {
ZStack {
Color
.black
.ignoresSafeArea(.all)
VStack {
//---------------------------------------------------------------------------------
//Result display START
Spacer()
HStack{
Spacer()
if resultText == "" {
Text(defaultText)
.foregroundColor(.white)
.font(.system(size: 100))
}
else if resultText.count <= 6 {
Text(resultText)
.foregroundColor(.white)
.font(.system(size: 100))
}
else if resultText.count > 6 && resultText.count < 13 {
Text(resultText)
.foregroundColor(.white)
.font(.system(size: 50))
}
}
.padding()
//Result display END
//---------------------------------------------------------------------------------
//Button display START
//Row 1
HStack {
Spacer()
Button(action: {
resultText = defaultText//left off here
}) {
makeCalcButtonText(buttonText: CalcButton.clear)
}
.buttonStyle(CalcButtonStyle())
Spacer()
Button(action: {
operatorChain.append(CalcButton.negative.rawValue)
}) {
makeCalcButtonText(buttonText: CalcButton.negative)
}
.buttonStyle(CalcButtonStyle())
Spacer()
Button(action: {
operatorChain.append(CalcButton.percent.rawValue)
}) {
makeCalcButtonText(buttonText: CalcButton.percent)
}
.buttonStyle(CalcButtonStyle())
Spacer()
Button(action: {}) {//pick up here
makeCalcButtonText(buttonText: CalcButton.divide)
}
.buttonStyle(CalcButtonStyle())
Spacer()
}
.padding()
//Row 2
HStack {
Spacer()
Button(action: {
}) {
makeCalcButtonText(buttonText: CalcButton.seven)
}
.buttonStyle(CalcButtonStyle())
Spacer()
Button(action: {
}) {//pick up here
makeCalcButtonText(buttonText: CalcButton.eight)
}
.buttonStyle(CalcButtonStyle())
Spacer()
Button(action: {
}) {//pick up here
makeCalcButtonText(buttonText: CalcButton.nine)
}
.buttonStyle(CalcButtonStyle())
Spacer()
Button(action: {}) {//pick up here
makeCalcButtonText(buttonText: CalcButton.multiply)
}
.buttonStyle(CalcButtonStyle())
Spacer()
}
.padding()
//Row 3
HStack {
Spacer()
Button(action: {
}) {
makeCalcButtonText(buttonText: CalcButton.four)
}
.buttonStyle(CalcButtonStyle())
Spacer()
Button(action: {
}) {
makeCalcButtonText(buttonText: CalcButton.five)
}
.buttonStyle(CalcButtonStyle())
Spacer()
Button(action: {
}) {
makeCalcButtonText(buttonText: CalcButton.six)
}
.buttonStyle(CalcButtonStyle())
Spacer()
Button(action: {}) {//pick up here
makeCalcButtonText(buttonText: CalcButton.subtract)
}
.buttonStyle(CalcButtonStyle())
Spacer()
}
.padding()
//Row 4
HStack {
Spacer()
Button(action: {
}) {
makeCalcButtonText(buttonText: CalcButton.one)
}
.buttonStyle(CalcButtonStyle())
Spacer()
Button(action: {
}) {
makeCalcButtonText(buttonText: CalcButton.two)
}
.buttonStyle(CalcButtonStyle())
Spacer()
Button(action: {
}) {
makeCalcButtonText(buttonText: CalcButton.three)
}
.buttonStyle(CalcButtonStyle())
Spacer()
Button(action: {}) {//pick up here
makeCalcButtonText(buttonText: CalcButton.add)
}
.buttonStyle(CalcButtonStyle())
}
.padding()
//Row 5
HStack {//error is present here
Spacer()
Button(action: {}) {//pick up here
makeCalcButtonText(buttonText: CalcButton.zero)
}
.buttonStyle(CalcButtonStyle())
Spacer()
Button(action: {}) {//pick up here
makeCalcButtonText(buttonText: CalcButton.decimal)
}
.buttonStyle(CalcButtonStyle())
Spacer()
Button(action: {}) {//pick up here
makeCalcButtonText(buttonText: CalcButton.equal)
}
.buttonStyle(CalcButtonStyle())
Spacer()
}
.padding()
Spacer()
}
}
}
}
After a while, I decided to move the computations into another swift file and leave the ContentView.swift file for the visual part. If I remove the following code:
@State var operatorChain: [String] = []
@State var oprandChain: [Double] = []
I will get the same exact error message. It is pretty counter productive, I'm just learning swift so that I can develop for current technologies in the market and I'm stuck with that. However, I may just leave them there for now, though they may or not be used.