Post

Replies

Boosts

Views

Activity

3 code errors
Hi, I am a new coder and I have 3 code errors in my app that I am making. Which are Value of type 'String' has no member 'frame' : line 174 Cannot infer contextual base in reference to member 'all': line 176 Closure containing a declaration cannot be used with function builder 'ViewBuilder' : line 186 Finally, here is my code: import SwiftUI struct ContentView: View {     @State private var currentCount = UserDefaults.standard.integer(forKey: "currentCount")     @State private var isDecrementOn = false          func performsMath(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")             }         }     }     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)                 }             }                                  ScrollView(.horizontal) {                          HStack(alignment: .center, spacing: 10) {                 Button(action: {                     self.performsMath(isSubtract: self.isDecrementOn, num: 1)                 }) {                     Text(isDecrementOn ? "-1" : "+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)                         ) }                     }                                                  struct ContentView_Previews: PreviewProvider {             static var previews: some View {                 ContentView()   }                 }             }         }     }} Could someone help me?
1
0
1.2k
Feb ’21