Post

Replies

Boosts

Views

Activity

Reply to cannot find in scope
Part 1. import SwiftUI struct ContentView: View { @State var tipa: [Double] = [] @State var costa: [Double] = [] @State private var cost = "" @State private var costt = Double?(0) @State private var paidt = Double?(0) @State private var paid = "" @State var tipp = "" @State var tipc = "" @State var tipaa = "" @State var totalcost = "" @State var totaltips = "" @State var totalcash = "" @State var tipcc = "" @State var numbc = "" @State var deletep = 0 @State var number = 0 @State var msg = "Enter cost and how much was paid. Enter numbers" @State var msg2 = " and one . decimal point only. Then press enter." @State var emsg = "" var body: some View { NavigationStack { VStack { Text(" " + Date().formatted(date: .numeric, time: .omitted)) .foregroundColor(.black) .fontWeight(.bold) Text("Driver's Food Delivery") .font(.largeTitle) .fontWeight(.bold) Image("Screenshot 2024") HStack { Text("Cost") .font(.largeTitle) .padding(10) Spacer() Text("Paid") .font(.largeTitle) .padding(10) Spacer() Text("Tip") .font(.title) Spacer() Text("Tip %") .font(.title) } HStack { TextField("Cost", text: $cost) .frame(width: 75, height: 25) .padding(20) .fontWeight(.bold) .font(.system(size: 22)) .foregroundColor(.blue) .background(Color.brown) .cornerRadius(025) TextField("Paid", text: $paid) .frame(width: 75, height: 25) .padding(20) .fontWeight(.bold) .font(.system(size: 22)) .foregroundColor(.blue) .background(Color.brown) .cornerRadius(025) Text(tipp) .frame(width: 95, height: 25) .background(Color.white) .fontWeight(.bold) .font(.system(size: 22)) .foregroundColor(.blue) Text(tipc) .frame(width: 75, height: 5) .padding(10) .background(Color.white) .fontWeight(.bold) .font(.system(size: 22)) .foregroundColor(.blue) } VStack { Text (emsg) .foregroundColor(.red) Text (msg) .foregroundColor(.blue) HStack { Text (msg2) .foregroundColor(.blue) Spacer() } Button { enterp() } label: { Text("Enter") .font(.largeTitle) .foregroundColor(.green ) } NavigationLink(destination: viewdetail()) { Text("Detail") .frame(width: 100, height: 50, alignment: .center) .background(Color.white) .foregroundColor(.blue) .font(.largeTitle) } Button { delete(costa:&costa,tipa:&tipa, number: &number) } label: { Text("Delete") .font(.largeTitle) .foregroundColor(.red) } } VStack { Spacer() HStack { Spacer() Text("Avg Tip") .font(.title) Spacer() Spacer() Text(" Tip %") .font(.title) Spacer() Text(" #") .font(.title) Spacer() } HStack { Spacer() Spacer() Spacer() Text(tipaa) .frame(width: 145, height: 25) .fontWeight(.bold) .font(.system(size: 22)) .foregroundColor(.blue) Spacer() Spacer() Text(tipcc) .frame(width: 120, height: 5) .padding(10) .fontWeight(.bold) .font(.system(size: 22)) .foregroundColor(.blue) Spacer() Text(numbc) .frame(width: 55, height: 5) .padding(10) .fontWeight(.bold) .font(.system(size: 22)) .foregroundColor(.blue) Spacer() } }
Dec ’24
Reply to cannot find in scope
Part 2. VStack { Spacer() HStack { Text("Total") .font(.title) Spacer() Text("Total") .font(.title) Spacer() Text("Total ") .font(.title) } } VStack { HStack { Text("Cost") .font(.title) Spacer() Text("Tips") .font(.title) Spacer() Text("Cash") .font(.title) } } HStack { Text(totalcost) .frame(width: 145, height: 25) .fontWeight(.bold) .font(.system(size: 22)) .foregroundColor(.blue) Spacer() Text(totaltips) .frame(width: 145, height: 25) .fontWeight(.bold) .font(.system(size: 22)) .foregroundColor(.blue) Spacer() Text(totalcash) .frame(width: 165, height: 25) .fontWeight(.bold) .font(.system(size: 22)) .foregroundColor(.blue) } Spacer() } } } func enterp() { @Binding var text1: String var ipc = 50.0 var ipcc = 50.0 var tippp = 0.0 var totalcsh = 0.0 var ttips = 0.0 var tcost = 0.0 var tipo = 0.00 costt = Double(cost) paidt = Double(paid) emsg = "" if (costt != nil) && (paidt != nil) { tipo = (Double(paid)! - Double(cost)!) tipa.append (tipo) costa.append (Double(cost)!) number += 1 numbc = String(number) ttips = (tipa.reduce(0, +)) tcost = (costa.reduce(0,+)) tippp = (ttips / Double(number)) tipaa = tippp.formatted(.currency(code: "USD")) totaltips = ttips.formatted(.currency(code: "USD")) totalcost = tcost.formatted(.currency(code: "USD")) tipp = tipo.formatted(.currency(code: "USD")) tipc = String(tipo / Double(cost)! * 100) ipc = Double (tipc)! tipc = String(format: "%3.0f%%", ipc) tipcc = String(ttips / tcost * 100) ipcc = Double (tipcc)! tipcc = String(format: "%3.0f%%", ipcc) totalcsh = (tcost + ttips) totalcash = totalcsh.formatted(.currency(code: "USD")) } else { emsg = "Enter numbers and 1 decimal point only." } // detailLine(costa: &costa,tipa: &tipa) } } } #Preview { ContentView() }
Dec ’24
Reply to cannot find in scope
Part 3 viewdetail.swift import SwiftUI struct viewdetail: View { @State var text1:String = "" @State var tip1:String = "" @State var text23:String = "" @State var tip23:String = "" var body: some View { Text(text1);Text(tip1);Text(text23);Text(tip23) } func detailLine(costa:inout [Double],tipa:inout [Double]) { print(costa,tipa) text1 = "125" print("detail") } } func delete(costa:inout [Double],tipa:inout [Double],number: inout Int) { print(costa,tipa) tipa.removeLast() costa.removeLast() number -= 1 print(costa,tipa) } #Preview { viewdetail() }
Dec ’24
Reply to cannot find in scope
I don't know how to do this.Let's assume the view that contains enterp() is called AnotherView. Then, in AnotherView define a Binding @Binding var text1ForUpdate: String // To make it easier to understand, I've not named it text1, but you could declare detailLine inside AnotherView somewhere in ViewDetail you call AnotherView pass the text1 as parameter: AnotherView(text1ForUpdate: $text1) Change ne name in detailLine func: text1ForUpdate = "125" Tell if that works now. Please help!!
Dec ’24
Reply to cannot find in scope
Can you explain this please. Let's assume the view that contains enterp() is called AnotherView. Then, in AnotherView define a Binding @Binding var text1ForUpdate: String // To make it easier to understand, I've not named it text1, but you could declare detailLine inside AnotherView somewhere in ViewDetail you call AnotherView pass the text1 as parameter: AnotherView(text1ForUpdate: $text1) Change ne name in detailLine func: text1ForUpdate = "125"
Dec ’24