NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

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


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


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:


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.


Correction: Card class should be Card struct.


Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until October 1st.

Click to save your free spot now

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

Reply to this topic…

You need to create an account or log in to reply.

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.