|
I have a ForEach iterating over 3 sets of data, inside the foreach there is a navigation link which passes @State variables to @Binding variables in the child view. The child view accepts data, processes it and passes it back to the parent view - all successfully. If you navigate to each of the three items from top to bottom, the information input on the child view from the first item still appears in the child view for the two subsequent items. If changed it will update the correct item in core data, and pass that back to the parent and show in the correct item, but which ever item you. navigate to subsequently the data from the first item in the set is loaded into the child view. It gets weirder-- If I start with the third item in the view and work upwords, it works more as expected, when you move to the second item, with the data in the child view set to the initial values in the second item, and not to whatever was entered in the third item. I tried clearning the binding variables in the child view before returning to the parent view, but that doesn’t seem to help. Apologize for the lengthy code, but couldn't figure out how to demonstrate the problem in a shorter way. Here are the screen shots of the parent and child views. https://www.dupscore.com/dupscore-v2-2
//MARK: ============ F U N C T I O N S ========================== //MARK: ========================================================== static func setTables (tt: Int) -> [Int] { var tables = [1] switch tt{ case 2: tables = [1,2] case 3: tables = [1,2,3] case 4: tables = [1,2,3,4] default: tables = [1,2,3,4,5] } return tables}
}
|
|
hi, as someone who has an interest in bridge scoring programs (i have one that's oriented toward Chicago rather than duplicate), i'd like to help, but all of us on the Forum could use some help on your end as well. your code is a little difficult to follow. first, i'd suggest some refactoring of the view into smaller views to help with readability. example: instead of
this would work much better
where we define
second, do you really need all of these @State variables? i think some readers of the Forum might see this and quickly move along to the next post. on the other hand, if you really do need many of these, why not use a single finally, i am puzzled by one construct above:
executing on the other hand, since you really just want to read values of the
(if each i look forward to see where you go with this. hope this helps, DMG |
|
Hello DelawareMathGuy, thanks very much for responding. I am "hobby" programmer, I guess and doing on my own, so apologize for the less than tight code. I get the refactoring, and will do that. getScores is getting the information for a single board played at a single table. It's calculating the index into the array and moving that data to the "bid" fields which are passed to the child view where the bid info is entered and results are calculated. Can't do a ForEach across the entire array because it contains score for all of the boards and I just need for each table on a single board. Will think about whether I could just pass the score row as a whole to the bidCalc(child view) instead of the individual items or maybe just board and table number, thereby reducing the individual items needed to be state variables. Since the purpose of the parent view is just navigation and board selection, that might make more sense. Not sure if the restructure will change the weird behavior, but I'll see. Score core data class is identifiable. The sequence of how swiftui triggers processing, or sees changes that trigger redraw is currently a challenge for me. |
|
hi Sandy, for the record, i am also a "hobby programmer," only in the sense that i write code for things that interest me, and try to help out others. i enjoy bridge (albeit Chicago-style with my local group that can have anywhere from 4 to 10 players each week). and i am also retired. so, keep going ... just a few comments for you right now.
this is probably not quite the right idea in SwiftUI. executing the body property and using a if you want to restrict the scores shown in the
and then define the computed property
and which elements of the scoreArray you pick out can be determined by another variable, whether it be a @State variable or not (it looks like you have a commented-out i also loved it when you stated what every reader of this Forum felt at some point:
yes, the mysteries still continue ... surely next week's WWDC will clear this all up (!) feel free to contact me directly, and i am happy to take a look at code if you wish ... you can find me on GitHub. hope that helps, DMG |
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.