Post

Replies

Boosts

Views

Activity

Reply to cannot find in scope
Okay, well, you went ahead anyway. Here's my update: // ContentView.swift import SwiftUI struct ContentView: View { @State private var tipa: [Double] = [] @State private var costa: [Double] = [] @State private var cost = "" @State private var costt: Double? = 0.0 @State private var paidt: Double? = 0.0 @State private var paid = "" @State private var tipp = "" @State private var tipc = "" @State private var tipaa = "" @State private var totalCost = "" @State private var totalTips = "" @State private var totalCash = "" @State private var tipcc = "" @State private var numbc = "" @State private var deletep = 0 @State private var number = 0 @State private var errorMsg = "" var body: some View { GeometryReader { g in NavigationStack { VStack { HStack { // No need to manually pad the date out with spaces, which will never be correct. // Just use an HStack and put a Spacer() in, so it goes: |<.....Spacer().....>Date| Spacer() Text(Date().formatted(date: .numeric, time: .omitted)) .foregroundStyle(Color.black) .fontWeight(.bold) .padding(.trailing, 10) } Text("Driver's Food Delivery") .font(.largeTitle) .fontWeight(.bold) Image("Screenshot 2024") VStack { Spacer() Text(errorMsg) .foregroundStyle(Color.red) // Here, put the text in one Text element, and tell SwiftUI to put it on two lines. // No need for msg/msg2 variables. Text("Enter cost and how much was paid. Enter numbers and one decimal point only, then press Enter.") .foregroundStyle(Color.blue) .lineLimit(2, reservesSpace: true) Spacer() } // Use a Grid to lay out your data; much cleaner, and SwiftUI will keep it in columns for you Grid(alignment: .center, horizontalSpacing: 6, verticalSpacing: 6) { GridRow { Text("Cost") .gridColumnAlignment(.leading) Text("Paid") .gridColumnAlignment(.leading) Text("Tip") .gridColumnAlignment(.trailing) Text("Tip %") .gridColumnAlignment(.trailing) } .font(.headline) GridRow { TextField("Cost", text: $cost) .padding(10) .background(Color.brown) .cornerRadius(12) .frame(width: g.size.width * 0.2) .gridColumnAlignment(.leading) TextField("Paid", text: $paid) .padding(10) .background(Color.brown) .cornerRadius(12) .frame(width: g.size.width * 0.2) .gridColumnAlignment(.leading) Text(tipp) .frame(width: g.size.width * 0.2) .gridColumnAlignment(.trailing) Text(tipc) .frame(width: g.size.width * 0.2) .gridColumnAlignment(.trailing) } } .padding(.vertical, 20) HStack { Button { enterPayment() } label: { Text("Enter") .font(.title2) .padding(10) .background(Color.green) .foregroundStyle(Color.white) .cornerRadius(12) } .padding(.leading, 10) // Keeps it off the edge of the screen NavigationLink(destination: ViewDetail()) { Text("Detail") .font(.title2) .padding(10) .background(Color.blue) .foregroundStyle(Color.white) .cornerRadius(12) } Spacer() // Leaves a gap between the Enter & Detail buttons, and the destructive Delete button Button { delete(costa: &costa, tipa: &tipa, number: &number) } label: { Text("Delete") .font(.title2) .padding(10) .background(Color.red) .foregroundStyle(Color.white) .cornerRadius(12) } .padding(.trailing, 10) // Keeps it off the edge of the screen } Divider() // Nice little divider .padding(.vertical, 20) } VStack { Grid(alignment: .center, horizontalSpacing: 6, verticalSpacing: 6) { GridRow { Text("Avg. Tip") .padding(.horizontal, 20) Text("Tip %") .padding(.horizontal, 20) Text("#") .padding(.horizontal, 20) } .gridColumnAlignment(.center) .font(.title3) GridRow { Text(tipaa) .padding(.horizontal, 20) Text(tipcc) .padding(.horizontal, 20) Text(numbc) .padding(.horizontal, 20) } .gridColumnAlignment(.center) .font(.system(size: 22, weight: .bold)) .foregroundStyle(Color.blue) } Spacer() } VStack { Grid(alignment: .center, horizontalSpacing: 6, verticalSpacing: 6) { GridRow { Text("Total Cost") .padding(.horizontal, 10) Text("Total Tips") .padding(.horizontal, 10) Text("Total Cash") .padding(.horizontal, 10) } .gridColumnAlignment(.center) .font(.title3) GridRow { Text(totalCost) .padding(.horizontal, 10) Text(totalTips) .padding(.horizontal, 10) Text(totalCash) .padding(.horizontal, 10) } .gridColumnAlignment(.center) .font(.system(size: 22, weight: .bold)) .foregroundStyle(Color.blue) } Spacer() } } } } func enterPayment() { var ttips = 0.0 var tcost = 0.0 var tipo = 0.00 costt = Double(cost) paidt = Double(paid) errorMsg = "" 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, +)) tipaa = (ttips / Double(number)).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) tipc = String(format: "%3.0f%%", Double(tipc)!) tipcc = String(ttips / tcost * 100) tipcc = String(format: "%3.0f%%", Double(tipcc)!) totalCash = (tcost + ttips).formatted(.currency(code: "USD")) } else { errorMsg = "Enter numbers and 1 decimal point only." } } } 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 { ContentView() }
Dec ’24
Reply to cannot find in scope
Don't post the whole program. Aside from the fact it's far too much code and you'll end up posting it over numerous posts, you still haven't mastered the use of the code formatting tool so we won't be able to understand it anyway. Please just reduce your code to the smallest bit possible - remove any formatting that's unnecessary, like fonts and padding etc. - you can add it back later. As @Claude31 was saying, use a Binding to pass values from one View to another, something like this: struct ViewOne: View { @State private var firstNames: [String] = ["Dave", "Geoff", "Bob", "Charlie"] var body: some View { Text("Some text") ViewTwo(firstNames: $firstNames) } } struct ViewTwo: View { @Binding firstNames: [String] var body: some View { firstNames.forEach { name in Text("Current name = '\(name)'") } } } That should display this: Some text Current name = 'Dave' Current name = 'Geoff' Current name = 'Bob' Current name = 'Charlie'
Dec ’24
Reply to Sound not working on iPad 7th generation
You should probably raise this as a bug in the usual way. It won't really get progressed if it's only posted in these Developer Forums. You need to raise each issue you find separately at https://feedbackassistant.apple.com/ You can post the FB numbers here if you want, so that others can link to them. We use these forums to ask for help on coding our apps; not for pointing out bugs in a beta version of the software. Please report bugs in the usual way.
Dec ’24
Reply to Rooted iPhone 15 Pro
You're in the wrong place. This is nothing to do with us. These are the Developer Forums, where developers of apps for Apple's platforms ask each other for hints and tips on coding. Your post is completely irrelevant to these forums, and I have marked it as such. Please don't post such things here again.
Topic: Privacy & Security SubTopic: General Tags:
Dec ’24
Reply to I submitted app to review on app store and am getting crash on libswiftCore.dylib. When I compile and run code through Xcode everything works fine
Well, all I can see is that thread 10 crashed with an address size fault, so you might be trying to access something like an element of an array that isn't there, maybe you're trying to get array[10] in an array that has ten items, i.e. array[0...9]? Maybe you're force-unwrapping an optional? You're honestly just going to have to debug it. You have the code, we don't.
Dec ’24
Reply to iOs update camera and flash issue
You're in the wrong place. Also, "since they have updated"? Updated to what? Which version are you seeing this in? When you provide the relevant details, people can help, but just saying you have an issue doesn't help anyone. These are the Developer Forums, where developers of apps for Apple's platforms ask each other for hints and tips on coding. Your question is more of a product support one, so I'd suggest you ask it over at the Apple Support Forums. Thanks.
Dec ’24
Reply to Timeline refresh issue for widget on ios 18.2
This is not how widgets work. The timeline is a series of snapshots of data, i.e. what should appear at the first date, then the second date, then the third etc. Your widget doesn't really run any code. You do not need a .init() method in your Entry struct, and I suspect your issue with it immediately flashing to the next timeline entry is because your Entry struct sets the date to .now for every entry. That struct should look something like this: struct EventEntry: TimelineEntry { public let date: Date let configuration: DynamicIntentWidgetPersonIntent let person: Person let type: FriendType } Then in the timeline you create a series of entries that reflect what should happen at various times. And note that you're limited to about 72 updates per day, and widgets aren't really deigned to update every few seconds, so adding 3 or 6 seconds to a date isn't going to guarantee that your widget gets updated when you think it will. Once you have a timeline set up you can see it in the preview in Xcode with something like this: #Preview(as: .systemSmall) { WidgetExtension() } timeline: { let person = //some Person object let currentDate: Date = Date.now for minuteOffset in stride(from: 0, to: (24 * 60), by: 20) { // every 20 mins for one day = 72 entries let entryDate = Calendar.current.date(byAdding: .minute, value: minuteOffset, to: currentDate, wrappingComponents: false)! EventEntry(date: entryDate, configuration: configuration, person: person, type: .whatever)) } } Scroll through the timeline at the bottom of the preview window to see how your widget changes over time. I have no idea how you're using the .init method and this whole FriendType thing, but I don't think it's working how you think it's working.
Topic: Programming Languages SubTopic: Swift Tags:
Dec ’24
Reply to Warnings - Failed to locate resource
I think those are internal to Apple's frameworks so you can ignore them. I've seen the "default.csv" one. However, if they annoy you, you can raise a feedback request to have them silenced. https://feedbackassistant.apple.com/
Replies
Boosts
Views
Activity
Dec ’24
Reply to cannot find in scope
Okay, well, you went ahead anyway. Here's my update: // ContentView.swift import SwiftUI struct ContentView: View { @State private var tipa: [Double] = [] @State private var costa: [Double] = [] @State private var cost = "" @State private var costt: Double? = 0.0 @State private var paidt: Double? = 0.0 @State private var paid = "" @State private var tipp = "" @State private var tipc = "" @State private var tipaa = "" @State private var totalCost = "" @State private var totalTips = "" @State private var totalCash = "" @State private var tipcc = "" @State private var numbc = "" @State private var deletep = 0 @State private var number = 0 @State private var errorMsg = "" var body: some View { GeometryReader { g in NavigationStack { VStack { HStack { // No need to manually pad the date out with spaces, which will never be correct. // Just use an HStack and put a Spacer() in, so it goes: |<.....Spacer().....>Date| Spacer() Text(Date().formatted(date: .numeric, time: .omitted)) .foregroundStyle(Color.black) .fontWeight(.bold) .padding(.trailing, 10) } Text("Driver's Food Delivery") .font(.largeTitle) .fontWeight(.bold) Image("Screenshot 2024") VStack { Spacer() Text(errorMsg) .foregroundStyle(Color.red) // Here, put the text in one Text element, and tell SwiftUI to put it on two lines. // No need for msg/msg2 variables. Text("Enter cost and how much was paid. Enter numbers and one decimal point only, then press Enter.") .foregroundStyle(Color.blue) .lineLimit(2, reservesSpace: true) Spacer() } // Use a Grid to lay out your data; much cleaner, and SwiftUI will keep it in columns for you Grid(alignment: .center, horizontalSpacing: 6, verticalSpacing: 6) { GridRow { Text("Cost") .gridColumnAlignment(.leading) Text("Paid") .gridColumnAlignment(.leading) Text("Tip") .gridColumnAlignment(.trailing) Text("Tip %") .gridColumnAlignment(.trailing) } .font(.headline) GridRow { TextField("Cost", text: $cost) .padding(10) .background(Color.brown) .cornerRadius(12) .frame(width: g.size.width * 0.2) .gridColumnAlignment(.leading) TextField("Paid", text: $paid) .padding(10) .background(Color.brown) .cornerRadius(12) .frame(width: g.size.width * 0.2) .gridColumnAlignment(.leading) Text(tipp) .frame(width: g.size.width * 0.2) .gridColumnAlignment(.trailing) Text(tipc) .frame(width: g.size.width * 0.2) .gridColumnAlignment(.trailing) } } .padding(.vertical, 20) HStack { Button { enterPayment() } label: { Text("Enter") .font(.title2) .padding(10) .background(Color.green) .foregroundStyle(Color.white) .cornerRadius(12) } .padding(.leading, 10) // Keeps it off the edge of the screen NavigationLink(destination: ViewDetail()) { Text("Detail") .font(.title2) .padding(10) .background(Color.blue) .foregroundStyle(Color.white) .cornerRadius(12) } Spacer() // Leaves a gap between the Enter & Detail buttons, and the destructive Delete button Button { delete(costa: &costa, tipa: &tipa, number: &number) } label: { Text("Delete") .font(.title2) .padding(10) .background(Color.red) .foregroundStyle(Color.white) .cornerRadius(12) } .padding(.trailing, 10) // Keeps it off the edge of the screen } Divider() // Nice little divider .padding(.vertical, 20) } VStack { Grid(alignment: .center, horizontalSpacing: 6, verticalSpacing: 6) { GridRow { Text("Avg. Tip") .padding(.horizontal, 20) Text("Tip %") .padding(.horizontal, 20) Text("#") .padding(.horizontal, 20) } .gridColumnAlignment(.center) .font(.title3) GridRow { Text(tipaa) .padding(.horizontal, 20) Text(tipcc) .padding(.horizontal, 20) Text(numbc) .padding(.horizontal, 20) } .gridColumnAlignment(.center) .font(.system(size: 22, weight: .bold)) .foregroundStyle(Color.blue) } Spacer() } VStack { Grid(alignment: .center, horizontalSpacing: 6, verticalSpacing: 6) { GridRow { Text("Total Cost") .padding(.horizontal, 10) Text("Total Tips") .padding(.horizontal, 10) Text("Total Cash") .padding(.horizontal, 10) } .gridColumnAlignment(.center) .font(.title3) GridRow { Text(totalCost) .padding(.horizontal, 10) Text(totalTips) .padding(.horizontal, 10) Text(totalCash) .padding(.horizontal, 10) } .gridColumnAlignment(.center) .font(.system(size: 22, weight: .bold)) .foregroundStyle(Color.blue) } Spacer() } } } } func enterPayment() { var ttips = 0.0 var tcost = 0.0 var tipo = 0.00 costt = Double(cost) paidt = Double(paid) errorMsg = "" 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, +)) tipaa = (ttips / Double(number)).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) tipc = String(format: "%3.0f%%", Double(tipc)!) tipcc = String(ttips / tcost * 100) tipcc = String(format: "%3.0f%%", Double(tipcc)!) totalCash = (tcost + ttips).formatted(.currency(code: "USD")) } else { errorMsg = "Enter numbers and 1 decimal point only." } } } 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 { ContentView() }
Replies
Boosts
Views
Activity
Dec ’24
Reply to cannot find in scope
Don't post the whole program. Aside from the fact it's far too much code and you'll end up posting it over numerous posts, you still haven't mastered the use of the code formatting tool so we won't be able to understand it anyway. Please just reduce your code to the smallest bit possible - remove any formatting that's unnecessary, like fonts and padding etc. - you can add it back later. As @Claude31 was saying, use a Binding to pass values from one View to another, something like this: struct ViewOne: View { @State private var firstNames: [String] = ["Dave", "Geoff", "Bob", "Charlie"] var body: some View { Text("Some text") ViewTwo(firstNames: $firstNames) } } struct ViewTwo: View { @Binding firstNames: [String] var body: some View { firstNames.forEach { name in Text("Current name = '\(name)'") } } } That should display this: Some text Current name = 'Dave' Current name = 'Geoff' Current name = 'Bob' Current name = 'Charlie'
Replies
Boosts
Views
Activity
Dec ’24
Reply to Sound not working on iPad 7th generation
You should probably raise this as a bug in the usual way. It won't really get progressed if it's only posted in these Developer Forums. You need to raise each issue you find separately at https://feedbackassistant.apple.com/ You can post the FB numbers here if you want, so that others can link to them. We use these forums to ask for help on coding our apps; not for pointing out bugs in a beta version of the software. Please report bugs in the usual way.
Replies
Boosts
Views
Activity
Dec ’24
Reply to Rooted iPhone 15 Pro
You're in the wrong place. This is nothing to do with us. These are the Developer Forums, where developers of apps for Apple's platforms ask each other for hints and tips on coding. Your post is completely irrelevant to these forums, and I have marked it as such. Please don't post such things here again.
Topic: Privacy & Security SubTopic: General Tags:
Replies
Boosts
Views
Activity
Dec ’24
Reply to How to renew my developer account
Sign in at developer.apple.com Click Account at the top. Click the "Membership details" card. You should see your membership details on there. There should be an auto-renew switch that should already be enabled. If it isn't, just toggle it on. That should set it to auto-renew when it's about to expire.
Replies
Boosts
Views
Activity
Dec ’24
Reply to Xcode on windows
Not going to happen. Xcode is a Mac app. Buy a Mac. You'll actually love it.
Replies
Boosts
Views
Activity
Dec ’24
Reply to I submitted app to review on app store and am getting crash on libswiftCore.dylib. When I compile and run code through Xcode everything works fine
Well, all I can see is that thread 10 crashed with an address size fault, so you might be trying to access something like an element of an array that isn't there, maybe you're trying to get array[10] in an array that has ten items, i.e. array[0...9]? Maybe you're force-unwrapping an optional? You're honestly just going to have to debug it. You have the code, we don't.
Replies
Boosts
Views
Activity
Dec ’24
Reply to Final iPhone External Design / Maximum Security Purpose
This is the wrong place for these sort of, erm, suggestions.
Replies
Boosts
Views
Activity
Dec ’24
Reply to I submitted app to review on app store and am getting crash on libswiftCore.dylib. When I compile and run code through Xcode everything works fine
It looks like it was being tested on an iPad. Have you tested it on an iPad, or an iPad in the Simulator?
Replies
Boosts
Views
Activity
Dec ’24
Reply to otential Optimization or Bug in UINavigationController Push Operation in iOS 18
It looks like you're raising a bug? Have you raised a Feedback report? If not, please do so at https://feedbackassistant.apple.com/ then post the FB number here.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Dec ’24
Reply to .navigationTitle causes hang when creating a new item on a separate page, then navigating back to a TabView with PageTabViewStyle that is displaying that data on iOS 18.2
I couldn't reproduce this. You should raise a bug then post the FB number here. https://feedbackassistant.apple.com/
Topic: UI Frameworks SubTopic: SwiftUI
Replies
Boosts
Views
Activity
Dec ’24
Reply to The screen doesn't work after turning on the developer mode
Haven't experienced this at all. I wonder if you can use iPhone Mirroring on a Mac with macOS Sequoia installed on it? I realise you have to enter your iPhone password on the actual iPhone to get iPhone Mirroring started, but perhaps this action will be possible? Give it a try?
Replies
Boosts
Views
Activity
Dec ’24
Reply to iOs update camera and flash issue
You're in the wrong place. Also, "since they have updated"? Updated to what? Which version are you seeing this in? When you provide the relevant details, people can help, but just saying you have an issue doesn't help anyone. These are the Developer Forums, where developers of apps for Apple's platforms ask each other for hints and tips on coding. Your question is more of a product support one, so I'd suggest you ask it over at the Apple Support Forums. Thanks.
Replies
Boosts
Views
Activity
Dec ’24
Reply to Timeline refresh issue for widget on ios 18.2
This is not how widgets work. The timeline is a series of snapshots of data, i.e. what should appear at the first date, then the second date, then the third etc. Your widget doesn't really run any code. You do not need a .init() method in your Entry struct, and I suspect your issue with it immediately flashing to the next timeline entry is because your Entry struct sets the date to .now for every entry. That struct should look something like this: struct EventEntry: TimelineEntry { public let date: Date let configuration: DynamicIntentWidgetPersonIntent let person: Person let type: FriendType } Then in the timeline you create a series of entries that reflect what should happen at various times. And note that you're limited to about 72 updates per day, and widgets aren't really deigned to update every few seconds, so adding 3 or 6 seconds to a date isn't going to guarantee that your widget gets updated when you think it will. Once you have a timeline set up you can see it in the preview in Xcode with something like this: #Preview(as: .systemSmall) { WidgetExtension() } timeline: { let person = //some Person object let currentDate: Date = Date.now for minuteOffset in stride(from: 0, to: (24 * 60), by: 20) { // every 20 mins for one day = 72 entries let entryDate = Calendar.current.date(byAdding: .minute, value: minuteOffset, to: currentDate, wrappingComponents: false)! EventEntry(date: entryDate, configuration: configuration, person: person, type: .whatever)) } } Scroll through the timeline at the bottom of the preview window to see how your widget changes over time. I have no idea how you're using the .init method and this whole FriendType thing, but I don't think it's working how you think it's working.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Dec ’24