user10081458
user10081458

Reputation:

SwiftUI - How do I limit the number of objects displayed in a ForEach

I have a ForEach list in my app that pulls data from core data. Can I limit the number of objects that the ForEach list shows? for example, I want to only show the first 10 objects from my core data entity.

Upvotes: 0

Views: 696

Answers (2)

Chris
Chris

Reputation: 8126

maybe in some cases the better solution would be to limit the fetchrequest, which is also quicker and less resource consuming

fetchrequest.fetchLimit = 10

Upvotes: 0

BokuWaTaka
BokuWaTaka

Reputation: 168

you can limit the fetch from core data. see How fetch 10 records each time from table using coredata

if youre looking to limit from ForEach instead of Core Data, you can iterator your collection using range:

ForEach(0 ..< 10) { index in 
  Text(Users[index].name)
}

Upvotes: 2

Related Questions