TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

How do I select multiple views?

Forums > SwiftUI

My app has multiple images that I want to move around. Then I would like to perform a region pick on several views and move to a different NavigationLink. Not sure how to do a region pick.

Thanks, Kelly

2      

More on the context, I am working on a card game and need to select say 3 of the cards in a hand as a meld/group. Once selected, I will remove them from the hand and put into a table meld area where the other players can see them. So, trying to think of a way to do a region select across the cards, have them highlighted for verification then move on to the meld area.

Thanks, Kelly

2      

I think it would be more helpful to approach the problem as how to select an individual card object rather than how to select the view displaying that card object.

Your Card class should have an id property to identify each card instance. When the user selects a card, you could add its id to an @State var that is an array storing the id's of the selected cards. (Alternatively, you could include a "selected" boolean property in the Card class.)

If you have the patience to work through it, an elaborate example is the card game designed in the first 8 lectures of the Stanford course on SwiftUI: https://cs193p.sites.stanford.edu/

2      

Thanks for your advice, I will look at the course for this and other ideas and use the 'id' / Bool method for selection. I am just surprised that I can't drag my curser over a region and have that select cards in that region. I am using 3 taps to discard and now a long press to select for meld.

2      

Correction: Card class should be Card struct.

2      

Hacking with Swift is sponsored by RevenueCat.

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.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

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.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.