UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: Need help with day 42 challenge 3 Moonshot project.

Forums > 100 Days of SwiftUI

As Paul said in the tip I made separate views for Grid and List, but got these errors with the Group

Referencing instance method 'navigationTitle' on 'Group' requires that 'EmptyCommands' conform to 'View'

Closure containing control flow statement cannot be used with result builder 'CommandsBuilder'

import SwiftUI

struct ContentView: View {
    @State private var showingGrid = true

    let astronauts: [String: Astronaut] = Bundle.main.decode("astronauts.json")
    let missions: [Mission] = Bundle.main.decode("missions.json")

    let columns = [
        GridItem(.adaptive(minimum: 150))
    ]

    var body: some View {
        NavigationView {
            Group {
                if showingGrid {
                    GridLayout(astronauts: astronauts, missions: missions)
                } else {
                    ListLayout(astronauts: astronauts, missions: missions)
                }
            }
            .navigationTitle("Moonshot")
            .toolbar {
                Button("Toggle") {
                    showingGrid.toggle()
                }
                .buttonStyle(.plain)
            }
            .background(.darkBackground)
            .preferredColorScheme(.dark)
        }
    }
}

1      

I tried your ContentView and it worked fine for me.

You could try cleaning your build folder, just in case it is become messy and confused Xcode. In the menu bar, under Product select Clean Build Folder. Alternatively use Shift + Command + K

1      

I changed Group to VStack then back to Group and it worked 😅 Also did what you told. Thanks for the reply.

1      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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.