Post

Replies

Boosts

Views

Activity

Reply to Unable to preview on latest Xcode
Sure it works. I've tested with Xcode 16.2, MacOS 14.7.2 and using iPhone 16 Pro simulator as in your case. How long ago did you install Xcode ? Are you sure installation is complete ? Or were you asked to download simulators. If so, did you do it ? Try to select another simulator, or restart Xcode. If that does not work, try to reinstall, from a different site. This one works well: https://xcodereleases.com
Dec ’24
Reply to cannot find in scope
Thanks for the code, but still difficult to understand how all parts fit together. Where do you call enterp() ? Is it from inside ViewDetail (in a Button action for instance) ? If so, enterp() should also be inside ViewDetail Elsewhere, from another View ? If so, then you should pass text1 as a Binding when calling the other View Problem is that text1 is both a State var and you want to update in a conventional func which is not View related. Please let us understand the overall architecture of your code.
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
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