The compiler is unable to type check this expression in reasonable time

HI Everyone, I’m currently following the IOS foundation Course (Module 4 lesson 11)
And I have this Error : The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions

within this code:

struct RecipeDetailView: View
{
    var recipe:Recipe
    
    @State var selectedServiceSize = 2
    
    var body: some View
    {
        ScrollView
        {
            VStack(aligment: .leading)
            {
                // MARK: Recipe Image
                Image(recipe.image)
                    .resizable()
                    .scaledToFill()
                // MARK: Serving Size Picker
                VStack(alignment: .leading)
                {
                    Text("Select your serving size: ")
                    Picker("", selection: $selectedServiceSize)
                    {
                        Text("2").tag(2)
                        Text("4").tag(4)
                        Text("6").tag(6)
                        Text("8").tag(8)
                    }.pickerStyle(SegmentedPickerStyle())
                    .frame(width: 160)
                }
                // MARK: Ingredients
                VStack(alignment: .leading)
                {
                    Text("Ingredients")
                        .font(.headline)
                        .padding(.vertical, 5)
                    ForEach(recipe.ingredients)
                    {   ingredient in
                        Text("- " + ingredient.name)
                    }
                }.padding(.horizontal)
                // MARK: Divider
                Divider()
                // MARK: Directions
                VStack(alignment: .leading)
                {
                    Text("Directions")
                        .font(.headline)
                        .padding(.vertical, 5)
                    ForEach(0..<recipe.directions.count, id: \.self)
                    {   index in
                        
                        Text(String(index + 1) + " - " + recipe.directions[index])
                            .padding(.bottom, 5)
                        
                    }
                }
            }
        }.navigationBarTitle(recipe.name)
    }
}

I tried a few things including rewriting it and copy words for words Chris’s code but the same problem occurs even when I try to copy paste his file content

Did someone has the same problem?
Thanks in advance

In your first VStack, you have:

VStack(aligment: .leading)

It should be:

VStack(alignment: .leading)

Erfff Thanks you, but do you know why it doesn’t just show me that?

Xcode doesn’t always report SwiftUI errors correctly. That and a resigned shrug is about all the answer I have to give.

Also, if you simplify your code you can sometimes get better error messages. For instance:

I originally thought the error would be due to this line:

Text(String(index + 1) + " - " + recipe.directions[index])

because you take an Int, change it to a String, append another String, then append a third String, which can be a lot for the compiler to deal with as it tries to typecheck everything.

So I simplified it using string interpolation:

Text("\(index + 1) - \(recipe.directions[index])")

And that changed the error message from

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

to

Incorrect argument label in call (have 'aligment:_:', expected 'alignment:_:')

That’s not to say the original code was wrong, but it could be better in a way that makes sure the compiler doesn’t have to work too hard to figure stuff.

Okey thanks a lot that is really useful!
will try to simplify that!