[ad_1]
I’ve a listing with a nested ForEach loop that ought to take the information and cease producing rows as soon as the row counter hits three, however I am receiving the next error message
Sort ‘()’ can’t conform to ‘View
Is it doable to chop off the loop as soon as now we have three rows displaying? My finish purpose is as soon as three rows are displayed, to point out a “View Extra” button.
import SwiftUI
struct RecipeListView: View {
@State var listofRecipes: [RecipeListModel] = RecipeList.recipes
@State non-public var recipeCounter = 0
init(){
UITableView.look().backgroundColor = .clear
}
var physique: some View {
VStack{
Textual content("Recipes")
.padding(.backside, -20)
//.padding(.prime, 40)
.font(.title2)
Listing{
ForEach(listofRecipes, id: .id){ recipe in
recipeCounter += 1
if(recipeCounter < 3){
HStack{
Picture(recipe.picture)
.resizable()
.body (width: 70, top:70)
.cornerRadius(15)
VStack{
Textual content(recipe.title)
.font(.title2)
//temp answer till I can heart it
.padding(.trailing, 25)
NavigationLink(vacation spot: {RecipeController(title: recipe.title, picture: recipe.picture)}, label: {
Textual content("View Recipe")
.padding(5)
.foregroundColor(.black)
.background(Coloration("completeGreen"))
.body(maxWidth: .infinity)
.cornerRadius(14)
})
.padding(4)
}
}
}
}
}
}
}
}
[ad_2]
