Post

Replies

Boosts

Views

Activity

Reply to cannot find in scope
The code you post doesn't show where you call detailLine. How do you want anyone to guess ? Please show comprehensive code so that we can understand what you are trying to do. Code formatter is the 4th icon from the left below the Edit area when you edit a post. select the whole code text click on the formatter tool
Dec ’24
Reply to Differences between SwiftUI in Monterey and Sequoia
Yes, the syntax you are looking for would be convenient… But you can do it a bit differently. Like this func conditionalRect() -> some View { if #available(macOS 16.0, *) { return RoundedRectangle(cornerRadius: 1) .padding(.horizontal, -2.0) .frame(height: 4.0) } else { return RoundedRectangle(cornerRadius: 1) .padding(.horizontal, -4.0) .frame(height: 4.0) } } Or more simply, create a computed var var horizPadding : CGFloat { if #available(macOS 16.0, *) { return -2.0 } else { return -4.0 } } Then call RoundedRectangle(cornerRadius: 1) .padding(.horizontal, horizPadding) .frame(height: 4.0)
Topic: UI Frameworks SubTopic: SwiftUI
Dec ’24
Reply to Cannot find 'detailline' in scope
No one forgot you. But without the code it was just impossible to give an answer. Now, you've got the answer in the other thread. With the code, it was obvious to find the error. text1 was used in a function that was outside the scope where text1 was declared. Don't forget to close this thread as well.
Dec ’24
Reply to cannot find in scope
It's normal, it is out of scope : If you format the code properly: 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" // Cannot find 'text1' in scope print("detail") } func îs defined OUT of viewDetail. Hence, text1 in detailing is not defined. You have to change as follows: struct ViewDetail: View { @State var text1:String = "" @State var tip1:String = "" @State var text23:String = "" @State var tip23:String = "" func detailLine(costa:inout [Double],tipa:inout [Double]) { print(costa,tipa) text1 = "125" // Now, Can find 'text1' in scope print("detail") } var body: some View { Text(text1);Text(tip1);Text(text23);Text(tip23) } } Note also I changed the caps on names to follow Swift rules. PS: when you ask a question: format code with code formatter tool take time to formulate the question in the text, not only the title. Don't forget to close the thread once you've got the correct answer, by marking the answer as correct.
Dec ’24
Reply to the compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions
Welcome to the forum. Yes, it is probably one of the most frustrating error message of SwiftUI, with no indication at all where the problem is coming from. And there may be may causes. The only solutions I've found are: if you have a recent version that did work, compare the offending View with the previous one and detect what has changed Go by dichotomy: comment out a significant part (about half) of the body code if still fails, then error is in the other part ; so comment out half of this other part if is works, then I uncomment half of the commented and test again… That's the best I've found. Post the complete code of the View on the forum so that one can search
Topic: Programming Languages SubTopic: Swift Tags:
Dec ’24
Reply to SwiftUI: How to create different background colors for List sections?
Did you try to use listRowBackground ? I don't know if that's what you are looking for, but I've built an example from your code (replacing Query by State), with dummy structure for Medication. struct ProtocolMedication: Identifiable { // Should be completed with images, dates and other indications var id = UUID() var name : String } struct HomeView: View { /*@Query*/ @State private var protocolMedications: [ProtocolMedication] = [ProtocolMedication(name: "Testosterone"), ProtocolMedication(name: "Penicilin")] var body: some View { NavigationStack { List { // Upper sections with default background Section { Text("Content 1") } header: { Text("Log") } // Bottom section that needs different background Section { ForEach(protocolMedications) { medication in Text(medication.name) .listRowBackground(Color.green) } } header: { Text("Your Medications") } } .listStyle(.insetGrouped) } } } Here is the result: Interesting post here: https://sarunw.com/posts/swiftui-list-row-background-color/
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’24
Reply to VStack within ScrollView on macOS 15.2 makes bottom area unclickable
I tested in Xcode 16.2 with iOS 18.1 simulator, MacOS 14.7. It works with horizontal and VStack (even though buttons are squeezed in the lower left corner). I doubt the problem may come from macOS version. Same in Xcode 15.3 with iOS 18.1 simulator. Same with Xcode 15.0.1 and simulator 18.0. Could you test the modified code to see if it works on real device (and simulator): struct ContentView: View { @State private var showFoo = false @State private var showBar = false var body: some View { ScrollView(.horizontal) { VStack { Spacer() // this button is clickable Button("foo") { print("foo") showFoo.toggle() } // this button can't be clicked Button("bar") { print("bar") showBar.toggle() } if showFoo { Text("Foo")} if showBar { Text("Bar")} } } } }
Topic: UI Frameworks SubTopic: SwiftUI
Dec ’24
Reply to I don’t think the math is mathing. How is this possible?
This is a question about an existing app (you don't tell which unfortunately), not for an app development. So this forum is not the right place to post the question.   is there a way to fix this? You should ask on the app's developer forum. For some reason, the app has registered a total screen time of 139h05'. But only a small part falling in one of the categories. Hence, an average oh 19h52' per day (math is exact). It is up to you to understand how total screen time is accounted depending on the settings you may have defined.
Dec ’24
Reply to Updating EditButton
This thread may provide some hints: https://www.hackingwithswift.com/forums/swiftui/list-view-stuck-in-edit-mode/7401 It tested this, which apparently does what you need: struct ContentView: View { @State private var selects: Set<Int> = [] @State var range = [1, 2, 3 ,4, 5] @Environment(\.editMode) var editMode var body: some View { VStack{ EditButton() List(selection: $selects){ ForEach(range, id: \.self) { ItemInList(num: $0) } .onDelete { range.remove(atOffsets: $0) editMode?.wrappedValue = .inactive } } .listStyle(PlainListStyle()) } } }
Dec ’24
Reply to On a brand new build, why would I get this error: "Error creating the CFMessagePort needed to communicate with PPT."
I get the same message in log when creating a project in Xcode 16.2 on MacMini with MacOS 14.7.2. Error creating the CFMessagePort needed to communicate with PPT. Failed to send CA Event for app launch measurements for ca_event_type: 0 event_name: com.apple.app_launch_measurement.FirstFramePresentationMetric Failed to send CA Event for app launch measurements for ca_event_type: 1 event_name: com.apple.app_launch_measurement.ExtendedLaunchMetrics I tested on Xcode 15.3 creating a new project does not show the log but another one: Logging Error: Failed to initialize logging system. Log messages may be missing. If this issue persists, try setting IDEPreferLogStreaming=YES in the active scheme actions environment variables. opening the project created with 16.2 crashed Xcode, even after changing project format to Xcode 15.3 from 16.0. As the Xcode 16,2 project works without problem, that seems to be just log noise. You could file a bug report however.
Topic: UI Frameworks SubTopic: SwiftUI
Dec ’24
Reply to cannot find in scope
The code you post doesn't show where you call detailLine. How do you want anyone to guess ? Please show comprehensive code so that we can understand what you are trying to do. Code formatter is the 4th icon from the left below the Edit area when you edit a post. select the whole code text click on the formatter tool
Replies
Boosts
Views
Activity
Dec ’24
Reply to Is a spam an appreciated participation in the forums ?
Just keep going on, with the same message of appreciation from so called "App Store Connect Engineer" which is probably App Store Connect Bot. IMHO, I fear this practice of bot answer is a very bad evolution for the forum, which value has long been developers speaking to developers, not to bots.
Replies
Boosts
Views
Activity
Dec ’24
Reply to Differences between SwiftUI in Monterey and Sequoia
Yes, the syntax you are looking for would be convenient… But you can do it a bit differently. Like this func conditionalRect() -> some View { if #available(macOS 16.0, *) { return RoundedRectangle(cornerRadius: 1) .padding(.horizontal, -2.0) .frame(height: 4.0) } else { return RoundedRectangle(cornerRadius: 1) .padding(.horizontal, -4.0) .frame(height: 4.0) } } Or more simply, create a computed var var horizPadding : CGFloat { if #available(macOS 16.0, *) { return -2.0 } else { return -4.0 } } Then call RoundedRectangle(cornerRadius: 1) .padding(.horizontal, horizPadding) .frame(height: 4.0)
Topic: UI Frameworks SubTopic: SwiftUI
Replies
Boosts
Views
Activity
Dec ’24
Reply to Cannot find 'detailline' in scope
No one forgot you. But without the code it was just impossible to give an answer. Now, you've got the answer in the other thread. With the code, it was obvious to find the error. text1 was used in a function that was outside the scope where text1 was declared. Don't forget to close this thread as well.
Replies
Boosts
Views
Activity
Dec ’24
Reply to cannot find in scope
It's normal, it is out of scope : If you format the code properly: 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" // Cannot find 'text1' in scope print("detail") } func îs defined OUT of viewDetail. Hence, text1 in detailing is not defined. You have to change as follows: struct ViewDetail: View { @State var text1:String = "" @State var tip1:String = "" @State var text23:String = "" @State var tip23:String = "" func detailLine(costa:inout [Double],tipa:inout [Double]) { print(costa,tipa) text1 = "125" // Now, Can find 'text1' in scope print("detail") } var body: some View { Text(text1);Text(tip1);Text(text23);Text(tip23) } } Note also I changed the caps on names to follow Swift rules. PS: when you ask a question: format code with code formatter tool take time to formulate the question in the text, not only the title. Don't forget to close the thread once you've got the correct answer, by marking the answer as correct.
Replies
Boosts
Views
Activity
Dec ’24
Reply to the compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions
Welcome to the forum. Yes, it is probably one of the most frustrating error message of SwiftUI, with no indication at all where the problem is coming from. And there may be may causes. The only solutions I've found are: if you have a recent version that did work, compare the offending View with the previous one and detect what has changed Go by dichotomy: comment out a significant part (about half) of the body code if still fails, then error is in the other part ; so comment out half of this other part if is works, then I uncomment half of the commented and test again… That's the best I've found. Post the complete code of the View on the forum so that one can search
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Dec ’24
Reply to SwiftUI: How to create different background colors for List sections?
Did you try to use listRowBackground ? I don't know if that's what you are looking for, but I've built an example from your code (replacing Query by State), with dummy structure for Medication. struct ProtocolMedication: Identifiable { // Should be completed with images, dates and other indications var id = UUID() var name : String } struct HomeView: View { /*@Query*/ @State private var protocolMedications: [ProtocolMedication] = [ProtocolMedication(name: "Testosterone"), ProtocolMedication(name: "Penicilin")] var body: some View { NavigationStack { List { // Upper sections with default background Section { Text("Content 1") } header: { Text("Log") } // Bottom section that needs different background Section { ForEach(protocolMedications) { medication in Text(medication.name) .listRowBackground(Color.green) } } header: { Text("Your Medications") } } .listStyle(.insetGrouped) } } } Here is the result: Interesting post here: https://sarunw.com/posts/swiftui-list-row-background-color/
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Dec ’24
Reply to VStack within ScrollView on macOS 15.2 makes bottom area unclickable
What is the point of Geometry reader ? I tested with GeometryReader in Xcode 16.2. It works. I'm surprised bug may come from MacOS 15.2 But file a bug report.
Topic: UI Frameworks SubTopic: SwiftUI
Replies
Boosts
Views
Activity
Dec ’24
Reply to VStack within ScrollView on macOS 15.2 makes bottom area unclickable
I tested in Xcode 16.2 with iOS 18.1 simulator, MacOS 14.7. It works with horizontal and VStack (even though buttons are squeezed in the lower left corner). I doubt the problem may come from macOS version. Same in Xcode 15.3 with iOS 18.1 simulator. Same with Xcode 15.0.1 and simulator 18.0. Could you test the modified code to see if it works on real device (and simulator): struct ContentView: View { @State private var showFoo = false @State private var showBar = false var body: some View { ScrollView(.horizontal) { VStack { Spacer() // this button is clickable Button("foo") { print("foo") showFoo.toggle() } // this button can't be clicked Button("bar") { print("bar") showBar.toggle() } if showFoo { Text("Foo")} if showBar { Text("Bar")} } } } }
Topic: UI Frameworks SubTopic: SwiftUI
Replies
Boosts
Views
Activity
Dec ’24
Reply to I don’t think the math is mathing. How is this possible?
This is a question about an existing app (you don't tell which unfortunately), not for an app development. So this forum is not the right place to post the question.   is there a way to fix this? You should ask on the app's developer forum. For some reason, the app has registered a total screen time of 139h05'. But only a small part falling in one of the categories. Hence, an average oh 19h52' per day (math is exact). It is up to you to understand how total screen time is accounted depending on the settings you may have defined.
Replies
Boosts
Views
Activity
Dec ’24
Reply to Feedback Assistant: „This Feedback will no longer be monitored, and incoming messages will not be reviewed.“
I do fear that some of those messages are automatically generated. making the dialog useless. May be someone from the FB Assistant can confirm or infirm my guess ?
Replies
Boosts
Views
Activity
Dec ’24
Reply to Only 'Users and Access' Visible on App Store Connect – Apps Not Showing
The only time I got a similar problem was because I was registered on several accounts and had not the required credentials for the account I was connecting to. This is selected in the right hand corner of appStoreConnect page.
Replies
Boosts
Views
Activity
Dec ’24
Reply to Updating EditButton
This thread may provide some hints: https://www.hackingwithswift.com/forums/swiftui/list-view-stuck-in-edit-mode/7401 It tested this, which apparently does what you need: struct ContentView: View { @State private var selects: Set<Int> = [] @State var range = [1, 2, 3 ,4, 5] @Environment(\.editMode) var editMode var body: some View { VStack{ EditButton() List(selection: $selects){ ForEach(range, id: \.self) { ItemInList(num: $0) } .onDelete { range.remove(atOffsets: $0) editMode?.wrappedValue = .inactive } } .listStyle(PlainListStyle()) } } }
Replies
Boosts
Views
Activity
Dec ’24
Reply to Trouble Seeing print debug statements
Welcome to the forum. Sorry for the trivial check. Are you sure the log panel (right one) is on display ?
Replies
Boosts
Views
Activity
Dec ’24
Reply to On a brand new build, why would I get this error: "Error creating the CFMessagePort needed to communicate with PPT."
I get the same message in log when creating a project in Xcode 16.2 on MacMini with MacOS 14.7.2. Error creating the CFMessagePort needed to communicate with PPT. Failed to send CA Event for app launch measurements for ca_event_type: 0 event_name: com.apple.app_launch_measurement.FirstFramePresentationMetric Failed to send CA Event for app launch measurements for ca_event_type: 1 event_name: com.apple.app_launch_measurement.ExtendedLaunchMetrics I tested on Xcode 15.3 creating a new project does not show the log but another one: Logging Error: Failed to initialize logging system. Log messages may be missing. If this issue persists, try setting IDEPreferLogStreaming=YES in the active scheme actions environment variables. opening the project created with 16.2 crashed Xcode, even after changing project format to Xcode 15.3 from 16.0. As the Xcode 16,2 project works without problem, that seems to be just log noise. You could file a bug report however.
Topic: UI Frameworks SubTopic: SwiftUI
Replies
Boosts
Views
Activity
Dec ’24