Home > Mobile >  Configure preview for ObservedObject and State object
Configure preview for ObservedObject and State object

Time:11-19

So I am still learning Swift and for some reason, I am having the hardest trouble with the previews and how to configure them.

So I have the following code:

struct MainView: View {
    
    // The app's model that the containing scene passes in
    @ObservedObject var model: MainViewModel
    @State var activeTab = 0
    
    var body: some View {
        VStack {
            TabView(selection: $activeTab) {
                Group {
                    WorldView(model: model, activeTab: $activeTab)
                        .tabItem {
                            Label(Tabs.explore.rawValue, systemImage: Tabs.explore.icon)
                                .environment(\.symbolVariants, .none)
                        }
                        .tag(0)
                    ListView(model: model, activeTab: $activeTab)
                        .tabItem {
                            Label(Tabs.list.rawValue, systemImage: Tabs.list.icon)
                                .environment(\.symbolVariants, .none)
                        }
                        .tag(1)
                    FavoritesView(activeTab: $activeTab)
                        .tabItem {
                            Label(Tabs.favorite.rawValue, systemImage: Tabs.favorite.icon)
                                .environment(\.symbolVariants, .none)
                        }
                        .tag(2)
                    ProfileView(model: model, activeTab: $activeTab)
                        .tabItem {
                            Label(Tabs.profile.rawValue, systemImage: Tabs.profile.icon)
                                .environment(\.symbolVariants, .none)
                        }
                        .tag(3)
                }
                .environmentObject(model)
            }
            .tint(.accentColor)
            .onChange(of: activeTab, perform: { value in
                log.info("\n            
  • Related