Post

Replies

Boosts

Views

Activity

Reply to Failed to product diagnostic error
Yes, you are doing something (in fact several things) wrong. But to tell you what, you should show the complete Rosa structure. However, some problems: @State private var selezioneGiocatore: Rosa.ID? = nil Selection must be a Set, as @State private var selezioneGiocatore: Set<Rosa.ID> = [] TableColumn(Text("Età").foregroundStyle(.blue)) { Rosa in Text("\(Rosa.etàGiocatore)") } Using the structure name (Rosa) as the argument of the closure is incorrect. Rosa.testRosa().append(nuovoGiocatore) How is testRosa defined ? Seems to be a func ? append is trying to modify the structure, which is forbidden. You should call it on an instance as: var rosa = Rosa.testRosa() rosa.append(nuovoGiocatore) So please show complete code.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’24
Reply to 关于隐私清单
I would like to know for users who have not updated the app after May 1, will they be affected? 我想知道对于5月1日之后,用户如果没有更新app,是否会受到影响? 用户不应受到影响。只有开发人员在提交新版本时才需要修改应用程序。 Users should not be affected. Only developers have to modify the app when they submit a new version.
Mar ’24
Reply to Delay Issue with onChange Modifier in SwiftUI
Explanation is simple. Error comes from the fact that modelIndex used in selection may not be valid because there is no brand selected or because for the selected brand models count is lower than the current selection. And, as you noticed, the view is redrawn before on change is completed. By moving the if brandIndex != 0 test upward, you avoid the error when you select 'no brand'. Then, you don't see the picker but the Text asking to select a brand. But that was not enough. For instance, if you selected Renault Zoe (modelIndex = 3) and then select Porsche (only 2 models), view is updated and fails because modelIndex is still 3 (onChange not yet executed). With the change, if brandIndex != 0 && modelIndex <= cars[brandIndex - 1].models.count { // <<-- test modelIndex Picker("Model", selection: $modelIndex) { Text("Model Seçin").tag(0) // if brandIndex != 0 { let _ = print("modelIndex", modelIndex) // I'm getting first 3 then 0. And I'm getting error. ForEach(cars[brandIndex - 1].models.indices, id: \.self) { Text(cars[brandIndex - 1].models[$0]) .tag($0 + 1) } } } else { Text("Select a brand") } and not with: } else { // This section for design Picker("Model", selection: $modelIndex) { Text("Seçin").tag(0) } } then when you select Porsche, count is not OK, so you display Text("Select a brand") but you have no time to see, as onChange fires and then you see the Picker selection. To have time to see it, change the onChange as follows: .onChange(of: brandIndex) { print("changing brand", brandIndex) DispatchQueue.main.asyncAfter(deadline: .now() + 1) { // <<-- To get time to see the Text displayed if modelIndex != 0 { modelIndex = 0 } } } If that works, don't forget to close the thread on the correct answer. Otherwise explain the use case and the error.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’24
Reply to Delay Issue with onChange Modifier in SwiftUI
@ FiratSirin You're right, you need an additional test: if brandIndex != 0 && modelIndex <= cars[brandIndex - 1].models.count { // <<-- test modelIndex Picker("Model", selection: $modelIndex) { Text("Model Seçin").tag(0) // if brandIndex != 0 { let _ = print("modelIndex", modelIndex) // I'm getting first 3 then 0. And I'm getting error. ForEach(cars[brandIndex - 1].models.indices, id: \.self) { Text(cars[brandIndex - 1].models[$0]) .tag($0 + 1) } } } else { Text("Select a brand") } Here is the complete code I tested: struct Car: Decodable, Identifiable { enum CodingKeys: CodingKey { case brand case models } var id = UUID() var brand: String var models: [String] } struct ContentView: View { @State var brandIndex = 0 @State var modelIndex = 0 var cars : [Car] = [ Car(brand: "VW", models: ["Golf", "Passat", "Up"]), Car(brand: "Renault", models: ["Megane", "Twingo", "Zoe"]), Car(brand: "Porsche", models: ["Carrera", "Taycan"]) ] var body: some View { Picker("Marka", selection: $brandIndex) { Text("Marka Seçin").tag(0) ForEach(cars.indices, id: \.self) { Text(cars[$0].brand).tag($0 + 1) } } .onChange(of: brandIndex) { print("changing brand", brandIndex) if modelIndex != 0 { modelIndex = 0 } } if brandIndex != 0 && modelIndex <= cars[brandIndex - 1].models.count { Picker("Model", selection: $modelIndex) { Text("Model Seçin").tag(0) // if brandIndex != 0 { let _ = print("modelIndex", modelIndex) // I'm getting first 3 then 0. And I'm getting error. ForEach(cars[brandIndex - 1].models.indices, id: \.self) { Text(cars[brandIndex - 1].models[$0]) .tag($0 + 1) } } } else { Text("Select a brand") } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’24
Reply to Delay Issue with onChange Modifier in SwiftUI
Just move the if brandIndex != 0 { test if brandIndex != 0 { Picker("Model", selection: $modelIndex) { Text("Model Seçin").tag(0) // if brandIndex != 0 { let _ = print("modelIndex", modelIndex) // I'm getting first 3 then 0. And I'm getting error. ForEach(cars[brandIndex - 1].models.indices, id: \.self) { Text(cars[brandIndex - 1].models[$0]) .tag($0 + 1) } } } else { Text("Select a brand") }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’24
Reply to Access an Object and Change Values. up to 2 Class Levels down
Here is an example if I understand correctly what you want to achieve. I have changed some var names to make it clearer for me when coding. I also removed the @Model for this test. /*@Model*/ class Father { var name: String = "" var child: Child? } /*@Model*/ class Child { var name: String = "" var grandChild: GrandChild? var father: Father = Father() } /*@Model*/ class GrandChild { var name: String = "" var parent: Child = Child() } struct ContentView: View { @State var fatherEd = Father() @State var childBob = Child() @State var grandChildTom = GrandChild() @State var someChange = false // a trick to force a state change and force redraw ; could be replaced by Observed, but simpler here init() { grandChildTom.name = "Tom" grandChildTom.parent = childBob childBob.name = "Bob" childBob.grandChild = grandChildTom childBob.father = fatherEd fatherEd.name = "father Eduard" fatherEd.child = childBob } var body: some View { VStack { Text("Hello") Spacer() .frame(height: 20) if someChange || !someChange { Text("father:\(fatherEd.name)") Spacer() .frame(height: 20) if fatherEd.child != nil { Text("child:\(childBob.name)") Text("same as \(fatherEd.child!.name)") } Spacer() .frame(height: 20) if fatherEd.child?.grandChild != nil { Text("grandchild:\(grandChildTom.name)") Text("same as \(fatherEd.child!.grandChild!.name)") } Spacer() .frame(height: 20) } Button(action: { // Change the grandChild name through the child if someChange { fatherEd.child?.grandChild?.name = "Tom" } else { fatherEd.child?.grandChild?.name = "Laureen" } someChange.toggle() // just to force a change in the state var. }) { if someChange { Text("Revert grandChild name to Tom") } else { Text("Change grandChild name to Laureen") } } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’24
Reply to 0 of 3 App Previews
0 of 3 App Previews What do you mean? You have zero previews ? What is the rejection message you received ? The purpose of the screenshots is to provide screenshots (in the different device format required) to help user understand what your app does for him/her. It is not a tutorial even less a user manual. No need for video.   I'm unsure how to proceed with this. If I understand correctly your question, in simulator (for each device size that is required, for every language you support) do a screen capture (ctrl-S)
Mar ’24
Reply to How to using SwiftUI, develop a complex layout page for a social media app?
Your question is a bit general, so just some general comments. In SwiftUI, you should decompose your complex page in views Each subview being a logical block Several subviews being included in a VStack or HStack For the layout itself, it is (IMHO) one of the limits of SwiftUI: you have not the constraints manager as with UIKit. For data flow, sharing information either with .environment or State / Binding User interaction: what is your point ? Is it a need to focus on next item to enter (if so, use focusStats) Provide code snippets and explanations That's not how the fforum work. You don't ask others to do somethging. You should show what you did so far and explain what is not working as expected.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’24
Reply to Changing background color of a textview
You have to: declare fondbleu in a color asset catalog set the stack background: VStack { HStack { TextField("mot", text:$tfMot) .dynamicTypeSize(.xLarge) .disabled(true) .background(Color("fondbleu")) TextField("orthoAlt", text:$tfOrthoAlt, axis: .vertical) .dynamicTypeSize(.small) .background(Color("fondbleu")) .disabled(true) } TextField("Définition", text:$tfDefinition, axis: .vertical) .background(Color("fondbleu")) .disabled(true) } .background(Color("fondbleu"))
Mar ’24
Reply to Cannot cancel a submission. "You have an App Review submission cancellation in progress. You can resubmit items for review again after the cancellation is complete."
I contacted the app review team but have not got reply so far. How did you contact them (in appstore connect ?) is so, they don't usually answer. You'd better contact support. I once had a similar problem after cancelling a submission. What I did (I don't know if you can): proceeded to complete the initial submission immediately submit a new version It is not ideal as that leaves a bugged version, but I did not find another way at the time. Now, I never cancel submission anymore.
Mar ’24
Reply to when I add new line on my code, it stop responding showing rainbow loading
Hard to say with so limited information. Could you show the context ? is it SwiftUI code, with active preview ? Does it happen when you add code anywhere in the project or at some specific place ? if at specific place, please show the code. Does it occur for whatever code you insert or only for some specific code ? if specific, please show. which version of Xcode, MacOS ?
Mar ’24