I got this xcode error during work on the extra credits for this project:
Failed to produce diagnostic for expression; please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project.
Can anyone tell me what I did that may have caused this??
I am lost... 😞
Sorry new to this coding thing .
It shows up as a code line error.
This is the code that produces the error :
//
// ContentView.swift
// WeSplit2
//
// Created by Rodney Pemberton on 10/29/21.
//
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 = [0, 10, 15, 20, 25, 30]
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.currencyCode ?? "USD"))
.keyboardType(.decimalPad)
.focused($amountisFocused)
Picker("Number of people", selection: $numberOfPeople) {
ForEach(1..<101) {
Text("\($0) people")
}
}
}
Section {
Picker("Tip percentage", selection: $tipPercentage) {
ForEach(tipPercentages, id: \.self) {
Text($0, format: .percent)
}
}
.pickerStyle(.menu)
} header: {
Text("How much tip \"percentage\" do you wnat to leave.")
}
Section {
Text(totalPerPerson, format: .currency(code: Locale.current.currencyCode ?? "USD"))
}
}
.navigationTitle("We split tip")
.toolbar {
Spacer()
ToolbarItemGroup(placement: .keyboard) {
Button("Completed") {
amountisFocused = false
}
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
//
// ContentView.swift
// WeSplit2
//
// Created by Rodney Pemberton on 10/29/21.
//
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 = [0, 10, 15, 20, 25, 30]
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.currencyCode ?? "USD"))
.keyboardType(.decimalPad)
.focused($amountisFocused)
Picker("Number of people", selection: $numberOfPeople) {
ForEach(1..<101) {
Text("\($0) people")
}
}
}
Section {
Picker("Tip percentage", selection: $tipPercentage) {
ForEach(tipPercentages, id: \.self) {
Text($0, format: .percent)
}
}
.pickerStyle(.menu)
} header: {
Text("How much tip \"percentage\" do you wnat to leave.")
}
Section {
Text(totalPerPerson, format: .currency(code: Locale.current.currencyCode ?? "USD"))
}
}
.navigationTitle("We split tip")
.toolbar {
Spacer()
ToolbarItemGroup(placement: .keyboard) {
Button("Completed") {
amountisFocused = false
}
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}