I can't limit my forEach for only 3 items inside my list.
I tried to group them or to just limit the list with only 3 items but I don't have the result I want. I have all entries of Firestore document.
import SwiftUI
import Firebase
import Ballcap
struct MainPage : View {
@ObjectBinding var dataSource: ItemDatabase = ItemDatabase()
var item: Item
var body: some View {
NavigationView {
List {
ForEach(self.dataSource.items.identified(by: \.id)) { item in
ShortArticleItem(item: item.data!)
.padding()
}
VStack(alignment: .leading) {
Text(self.item.categorie ?? "")
.font(.largeTitle)
.fontWeight(.black)
.multilineTextAlignment(.leading)
.foregroundColor(.black)
ForEach( self.dataSource.items.identified(by: \.id)) { item in
MediumArticleItem(item: item.data!)
}
}
}
.navigationBarTitle(Text("The News Place"))
}
}
I would like to have just the 3 last elements in my ForEach
If you are using Array you can always use the array function prefix(number)
to determine how many items you want to render
ForEach(arrayItem.prefix(5), id: \.id){ item in
//DO Something Here
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With