|
When I add cards(images) to a players hand, I want to then update the view to show the new cards, same if I delete cards from the hand. Thanks for the assist!
|
|
@formank may have skipped important lessons on the way
It appears you have skipped some valuable lessons. In short, it seems you are trying to mix procedural language skills with SwiftUI's declarative approach. In a procedural language, you would determine when some data was updated, then TELL the code what to draw in the next several lines. In a declarative approach, you setup a data source, and wire your view to simply display what's in the data source. Any time the data source changes, your view will draw according to the new values in your data. Declare what you want to SeeIn SwiftUI, your views should just reflect the state of your model. In your case you have a player's hand of cards. If that hand has four cards in it, your view should show four cards. If you add a card, the view will detect the change in your model and redraw itself automatically to display five cards. Just update your model, and the view will redraw itself. Sample CodeHere is some sample code for you to paste into a new project. Notice how the Also notice the buttons add a NEW card, or REMOVE an existing card. The Sample Code
Keep CodingAre you following the 100 Days of SwiftUI? You code suggests you missed some key concepts. I would recommend you revisit several of the earlier lessons. |
|
|
|
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.