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

SOLVED: Bucket List SwiftUI Tutorial 3_12

Forums > SwiftUI

I get this error when trying to compile this (The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions):

enum LoadingState {
    case loading, success, failed
}
struct LoadingView: View {
    var body: some View {
        Text("Loading")
    }
}

struct SuccessView: View{
    var body: some View {
        Text("Success!")
    }
}

struct FailedView {
    var body: some View {
        Text("Failed")
    }
}

struct ContentView: View {
    var loadingState = LoadingState.loading

    var body: some View {

        if loadingState == .loading {
            LoadingView()

        } else if loadingState == .success {
            SuccessView()

        } else if loadingState == .failed {
            FailedView()
        }

    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

1      

Hint:

Look closely at your ContentView's subviews.

One of these things is NOT like the others. One of these things just doesn't belong.....

1      

Found the missing ": View" on the FailedView struct, now I got that song in my head... :)

2      

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.