LAST CHANCE: Save 50% on all my Swift books and bundles! >>

How to check which tab the user is on?

Forums > SwiftUI

Hi all, So i have three tabs A, B and C and inside C theres is a menu. My goal is to close that menu whenever i change tabs. How can i do this? Another way of asking is, how can i check to see what tab the user is on?

  • Nick G


I think @Environment presentationMode

then u can write states for each view and by switching the views get which one is active from environment


Thanks for the answer, im not very experienced would it be possible for you to explain to me what the code would look like?


I tried doing something like this

 DiscoverView().onTapGesture {
                    Image(systemName: "globe")

But it doesnt print "hello" when the tab is clicked


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 July 28th.

Click to save your free spot now

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.