SwiftUI. Want to code in each page that’s connected to the tabBar

Hi!

So...

I’ve currently been working on an app, well an recipes app. I’ve currently created a TabBarView.swift where the code for the TabBar itself is an alone code, that’s what i think. Anyway, i wanna know how i can create separate SwiftUI (Files or View) for each page itself. Like for example when i press the home button on the TabBar i want to be able to create the content that’s gonna be in home, in a different file, so i easily can organize things, by category of the app, is that possible?

Im happy to share the code so you can understand it better on how to fix my problem.

Answered by Claude31 in 676780022

Hope I understand your problem…

Just create a New file in the project in Xcode (Fle > New > File), and select SwiftUIView Name it MySwiftUIView

Adapt the template code to what you want to present:

import SwiftUI

struct MySwiftUIView: View {
    var body: some View {
        Text("Hello, World!")
    }
}

struct MySwiftUIView_Previews: PreviewProvider {
    static var previews: some View {
        MySwiftUIView()
    }
}

Then, call it in the tabbar:

         TabView {
            MySwiftUIView()
                .tabItem {
                    Label("MyView", systemImage: "list.dash")
                }
Accepted Answer

Hope I understand your problem…

Just create a New file in the project in Xcode (Fle > New > File), and select SwiftUIView Name it MySwiftUIView

Adapt the template code to what you want to present:

import SwiftUI

struct MySwiftUIView: View {
    var body: some View {
        Text("Hello, World!")
    }
}

struct MySwiftUIView_Previews: PreviewProvider {
    static var previews: some View {
        MySwiftUIView()
    }
}

Then, call it in the tabbar:

         TabView {
            MySwiftUIView()
                .tabItem {
                    Label("MyView", systemImage: "list.dash")
                }

No that wasn’t it. I already have my tabBar done. I just wanna code what’s going to be in the pages. Not the tabBar.

SwiftUI. Want to code in each page that’s connected to the tabBar
 
 
Q