Here is the screenshot of the debug area. I attached the entire code after the screenshot.
I googled a bit, and used the method I found on youtube to print off the possible error, but still can't get what it means.
For the information, I used "step over " button to go to the upper line (#27) to print off the error. The actually breakpoint was #28 at Form
. I don't know if I'm looking at the right place though. I did so (using stepover) from what I learned in this video on debugging tutorial for beginners. https://www.youtube.com/watch?v=qPWfOkHcKdU
I mean, my code is almost identical to Paul's
(https://www.hackingwithswift.com/books/ios-swiftui/calculating-the-total-per-person)
I don't see anything wrong with NavigationView
or Form
. But the printed off error says it is some error about Content
Here is the code:
It is completely fine in the canvas (Option + Command +P) , but it gives me green breakpoint 1.1 everytime I run it in the simulateor (command + R)
import SwiftUI
struct ContentView: View {
@State private var numberOfPeople = 2
@State private var CheckAmount = 50
@State private var tipPercentage = 20
let percentages = [5,10,15,20,25]
var amountPerPerson: Double {
let people = Double(numberOfPeople )
let amount = Double (CheckAmount * (1 + tipPercentage/100))
let perPerson = amount / people
return perPerson
}
var body: some View {
NavigationView {
Form {
Section {
TextField ("CheckAmount", value: $CheckAmount, format: .currency (code: "USD"))
Picker ("number of people", selection:$numberOfPeople){
ForEach(2..<100) {
Text ("\($0) people ")
}
}
}
Section {
Picker ("choose tip percentage", selection: $tipPercentage){
ForEach (percentages, id: \.self) {
Text (($0), format: .percent)
}
}
.pickerStyle(.segmented)
}
header:{
Text ("Choose Tip Percentage")
}
Section {
Text ("per person is \(amountPerPerson)")
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}