The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions

Hello guys I have a question regarding this. I was following the course of the iOS Foundations (Module 4 Lesson 6) and coded what Chris did in his video. Still i got this “The compiler is unable to type check …” error. How is this possible ? Do you have any advice for me ? I found a similar thread to this topic but i didnt got the point how to solve it.

Below you can find the code just in case you need.

import SwiftUI

struct RecipeDetailView: View {

var recipe:Recipe

var body: some View {
    
    ScrollView {
        
        VStack(alignment: .leading) {
            
        // MARK: Recipe Image
        Image(recipe.image)
            .resizable()
            .scaledToFill()

        // MARK: Ingredients
        VStack(alignment: .leading) {
            Text("Ingredients")
                .font(.headline)
                .padding([.top, .bottom], 5)

            ForEach(recipe.ingredients, id:\.self){ item in
                Text("-" + item.name)

            }
        }
        .padding(.horizontal)


        // MARK: Divider
        Divider()
                        
        // MARK: Directions
        VStack(alignment: .leading) {
            Text("Directions")
                .font(.headline)
                .padding([.bottom, .top], 5)
            
            ForEach(0..<recipe.directions.count, id:\.self){ index in
                
                Text(String(index+1) + "." + recipe.directions[index])
                    .padding(.bottom, 5)
                
            }
        }
        .padding(.horizontal)
        }
    }
    .navigationBarTitle(recipe.name)
}

}

struct RecipeDetailView_Previews: PreviewProvider {
static var previews: some View {

    let model = RecipeModel()
    RecipeDetailView(recipe: model.recipes[0])
}

}

1 Like

Hi @Atha

Welcome to the Community.

Change your code for the ingredients from this:

        // MARK: Ingredients
        VStack(alignment: .leading) {
            Text("Ingredients")
                .font(.headline)
                .padding([.top, .bottom], 5)

            ForEach(recipe.ingredients, id:\.self){ item in
                Text("-" + item.name)

            }
        }
        .padding(.horizontal)

to this:

                // MARK: Ingredients
                VStack(alignment: .leading) {
                    Text("Ingredients")
                        .font(.headline)
                        .padding([.top, .bottom], 5)

                    ForEach(recipe.ingredients) { ingredient in
                        Text("-" + ingredient.name)

                    }
                }
                .padding(.horizontal)

recipe.ingredients are Identifiable so you don’t need to create an id: using .self

Also the parameter preceding in is an ingredient so you should name it that way so that it reads clearly.

3 Likes

Wow thanks a lot for your help it works now. But why does the error go away and why didn’t Chris had this problem in his video ? That confuses me a little bit

Yes i will do in future really appreciate your feedback

You can check your code against his.

Resources can now be found up at the top of the course in the “Introduction Section”. Depending on the Course you select there will be an option titled “Resources” or “Materials for this course”. Tap on that link and then on the next page presented on the right you will have a link that says “All resources, projects and code” or a button that says Download Materials".

This will take you to a DropBox page where you can see folders related to each Module. Tap on the Download button in the top right of the screen and you can download all of the Materials covering all of the Modules for the course… or… you can drill down to a particular Module (double click on the folder) and then tap on the Download button to download all of the resources for just that Module.

Thanks a lot I checked it and he did it the same way as you said…my bad.