Closure containing a declaration cannot be used with result builder 'ViewBuilder'

I'm new to Swift and I got this error today. I have another SwiftUI page with the same code but the error doesn't appear there.

    struct CardView: View {
        var location: String
        var description: String
        var imageName: String
        
        var body: some View {
            
            VStack{
                Image(imageName)
                    .resizable()
                    .aspectRatio(contentMode: .fill)
                    .frame(width: 300, height: 200) // Set a fixed height for each card
                    .background(Color.black.opacity(0.7))
                VStack(alignment: .leading) {
                    
                    Spacer()
                    
                    Text(location)
                        .padding(15)
                        .font(.headline)
                        .fontWeight(.bold)
                        .frame(width:300, alignment: .init(horizontal: .leading, vertical: .center))
                        .foregroundColor(.black)
                        .bold()
                        .background(Color.white)
                        .clipShape(RoundedCorner(radius: 10, corners: [.topLeft, .topRight]))
                        .padding([.leading, .trailing], -14)
                        .padding(.bottom, 10)
                        .offset(y: -213)
                        .offset(x: 28)
                    
                    Text(description)
                        .font(.body)
                        .foregroundColor(.black)
                        .frame(width:300, alignment: .init(horizontal: .leading, vertical: .center))
                        .background(Color.white)
                        .clipShape(RoundedCorner(radius: 10, corners: [.bottomLeft, .bottomRight]))
                        .padding([.leading, .trailing], 14)
                        .padding(.bottom, 10)
                        .multilineTextAlignment(.leading)
                        .lineLimit(nil)
                        .offset(y: 2)
                }
                .padding()
                .frame(width: 200)
                .fixedSize()
            }
            .frame(height: 350) // Ensure each card has a fixed height
            .background(Color.white)
            .cornerRadius(10)
            .shadow(radius: 5)
            .padding([.leading, .trailing], 5) // Add padding to the sides for spacing
        }
    }
}

}

Welcome to the forum.

Your code compiles and runs fine (just had to change RoundedCorners by RoundedRectangle and initialise the 3 vars).

I also removed the extra closing curly brackets at the end.

So where does the error occur ? Probably in a part of code you did not show.

Closure containing a declaration cannot be used with result builder 'ViewBuilder'
 
 
Q