Swift and Kingfisher

I can’t figure out what’s wrong here and why my app won’t build, any suggestions?

import SwiftUI
import Kingfisher

struct RecipeRow: View {
let recipe: Recipe

var body: some View {
    HStack {
        KFImage(URL(string: recipe.photoURLSmall ?? "") ?? nil) //Improved nil handling
            .resizable()
            .scaledToFill()
            .frame(width: 70, height: 70)
            .clipShape(RoundedRectangle(cornerRadius: 10))
            .placeholder {
                ProgressView()
                    .progressViewStyle(CircularProgressViewStyle(tint: .red))
            }
            .onFailure { error in
                //Log the error for debugging
                print("Image loading failed: \(error)")
                Image(systemName: "photo")
                    .resizable()
                    .frame(width: 70, height: 70)
                    .foregroundColor(.gray)
                    .clipShape(RoundedRectangle(cornerRadius: 10))
            }
            .accessibilityLabel("Recipe Image") //Added accessibility label


        VStack(alignment: .leading, spacing: 4) {
            Text(recipe.name)
                .font(.headline)
                .lineLimit(1)
                .accessibilityLabel("Recipe Name: \(recipe.name)") //Added accessibility label
            Text(recipe.cuisine)
                .font(.subheadline)
                .foregroundColor(.gray)
                .accessibilityLabel("Recipe Cuisine: \(recipe.cuisine)") //Added accessibility label
        }
        .padding(.leading, 10)
    }
    .frame(maxWidth: .infinity, alignment: .leading)
}

}

After clipShape or some other modifier, your type is some View instead of KFImage.

And View does not have placeholder modifier here.

You can reorder the modifier to fix it.

1 Like