Hi, I have to many errors but I was wondering if someone could help fix my code.
Thanks
struct ContentView: View {
@State private var currentCount = UserDefaults.standard.integer(forKey: "currentCount")
@State private var isDecrementOn = false
var body: some View
ScrollView() {
VStack(alignment: .center, spacing: 10) {
HStack(alignment: .center, spacing: 20) {
Button(action: {
self.isDecrementOn.toggle()
}) {
Image(systemName: isDecrementOn ? "minus" : "plus")
.font(.headline)
.foregroundColor(.blue)
aspectRatio(contentMode: .fit)
}
Button(action: {
self.currentCount = 0
UserDefaults.standard.set(0,forKey: "currentCount")
}) {
Image(systemName: "trash")
.font(.headline)
.foregroundColor(.red)
aspectRatio(contentMode: .fit)
}
}
Button( action: {
self.performsMath(isSubtract: self.isDecrementOn, num: 1)
})
Text("\(self.currentCount)")
.font(.title)
}
}
func ScrollView(.horizontal){
HStack(alignment: .center, spacing: 10){
Button(Text(isDecrementOn ? "-1" : "+1"), action: {
self.performsMath(isSubtract: self.isDecrementOn, num: 1)
},
Button(action: {
self.performsMath(isSubtract: self.isDecrementOn, num: 2)
},
Text(isDecrementOn ? "-2" : "+2",
Button(action: {
self.performsMath(isSubtract: self.isDecrementOn, num: 3)
},
Text(isDecrementOn ? "-3" : "+3",
Button(action: {
self.performsMath(isSubtract: self.isDecrementOn, num: 4)
},
Text(isDecrementOn ? "-4" : "+4",
Button(action: {
self.performsMath(isSubtract: self.isDecrementOn, num: 5)
},
Text(isDecrementOn ? "-5" : "+5",
Button(action: {
self.performsMath(isSubtract: self.isDecrementOn, num: 10)
},
Text(isDecrementOn ? "-10" : "+10"
.frame(width: 50)
.padding(.all)
func performMaths(isSubtract: Bool, num: Int) {)
var result = self.currentCount
if isSubtract == true{
result -= num
};else{
result += num
if result >= 0 {
currentCount = result
UserDefaults.standard.set(currentCount, forKey: "currentCount")
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
}
}
}}}
}
Post
Replies
Boosts
Views
Activity
Thank you! That worked any thanks for the tips for pasting. I have 2 more errors now.
The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions.
Do you know what that means and how to fix it? It is on this line: var body: some View
in the beginning.
Also, Expected expression in list of expressions and Expected expression. What does that mean?
Thank you everyone!