TabView in iOS 18 and XCode 16

One of the things that i like with the SwiftUI released with XCode 16 is the new way to write a TabView.

Now we can write:

struct ContentView: View {
    
    var body: some View {
        TabView {
            Tab("Contacts", systemImage: "rectangle.stack.person.crop.fill") {
                // Your View 1
                }
            }
            Tab("Chat", systemImage: "message.fill") {
                // Your View 2
            }
            Tab("Settings", systemImage: "gear") {
               // Your View 3
            }
        }
    }
}

In the Tab properties we define the title and the image, in the body the view that we want display when that tab is selected. It’s very clear way.

Instead before of that we have to do:

struct ContentView: View {
    
    var body: some View {
        TabView {
            // Your View1
            .tabItem(Label("Contacts", systemImage: "rectangle.stack.person.crop.fill"))
            // Your View2
            .tabItem(Label("Chats", systemImage: "message.fill"))
            // Your View3
            .tabItem(Label("Settings", systemImage: "gear"))
        }
    }
}

Less clear, we have to attach the .tabItem to every View, before declare the view and then the tabbar element.

In the next post i’ll disaplay a chat app example.

share this post with friends

Picture of Nicola De filippo

Nicola De filippo

I'm a software engineer who adds to the passion for technologies the wisdom and the experience without losing the wonder for the world. I love to create new projects and to help people and teams to improve

1 comment

Leave a comment

Your email address will not be published. Required fields are marked *

Who I am

I'm a software engineer who adds to the passion for technologies the wisdom and the experience without losing the wonder for the world. I love to create new projects and to help people and teams to improve.

Follow Me Here

Get The Latest Updates

Periodically receive my super contents on coding and programming

join the family;)

Recent Posts