Howdy,
Something else is going on & maybe it is the iPhone 14 Pro Max or ???, because I downloaded Paul's solution from the HWS+ page & ran it locally...exact same results as what I observed & for the curious here is a bit more detail of what is happening.
I came back & when I fired up xcode again the coloring & indenting was appropriate...I don't know why it wasn't the first time.
I don't like putting in a huge chunk of code, but a new & interesting wrinkle appeared...
The DONE button still does not appear in the Simulator...but it does in the Preview! AND, if that wasn't enough...the keyboard doesn't appear in the preview, but it does in the Simulator...
I would have written it all off as a bug or something which will be fixed in the next patch, except...science!
// Created by Baron Blackbird on 7/15/23.
//
import SwiftUI
struct ContentView: View {
@State private var checkAmount = 0.0
@State private var numberOfPeople = 2
@State private var tipPercentage = 20
@FocusState private var amountIsFocused: Bool
let tipPercentages = [10, 15, 20, 25, 0]
var totalPerPerson: Double {
let peopleCount = Double(numberOfPeople + 2)
let tipSelection = Double(tipPercentage)
let tipValue = checkAmount / 100 * tipSelection
let grandTotal = checkAmount + tipValue
let amountPerPerson = grandTotal / peopleCount
return amountPerPerson
}
var body: some View {
NavigationView {
Form {
Section {
TextField("Amount: ", value: $checkAmount, format: .currency(code: Locale.current.currency?.identifier ?? "USD"))
.keyboardType(.decimalPad)
.focused($amountIsFocused)
Picker("Number of People", selection: $numberOfPeople) {
ForEach(2..<100) {
Text("\($0) people")
}
}
}
Section {
Picker("Tip Percentage", selection: $tipPercentage) {
ForEach(tipPercentages, id: \.self) {
Text($0, format: .percent)
}
}
.pickerStyle(.segmented)
} header: {
Text("Percentage to Tip")
}
Section {
Text(totalPerPerson, format: .currency(code: Locale.current.currency?.identifier ?? "USD"))
}
}
.navigationTitle("We Split")
.toolbar {
ToolbarItemGroup(placement: .keyboard) {
Spacer()
Button("Done") {
amountIsFocused = false
}
}
}
}
}
}
#Preview {
ContentView()
}