Hello,
I am building a list in SwiftUI, using the @FetchRequest property wrapper to fetch core data entities, taking as input a fetch request which has the property fetchBatchSize set to 50.
import SwiftUI
import CoreData
extension Item {
static var listRequest: NSFetchRequest<Item> {
let request = Item.fetchRequest()
request.fetchBatchSize = 50
request.sortDescriptors = [NSSortDescriptor(keyPath: \Item.timestamp, ascending: true)]
return request
}
}
struct ContentView: View {
@Environment(\.managedObjectContext) private var viewContext
@FetchRequest(fetchRequest: Item.listRequest)
private var items: FetchedResults<Item>
var body: some View {
NavigationView {
List {
ForEach(items) { item in
Text(item.timestamp!, formatter: itemFormatter)
}
}
}
}
}
But when loading my list with 3000 items and having the argument -com.apple.CoreData.SQLDebug
enabled, there are 241 calls made to load my items 50 by 50 at a time. There is no mention of fetchBatchSize
in the documentation, but this feature of fetch request is really important to me when building App dealing with large datasets of objects.
Am I doing something wrong or is there any recommandation about large data sets performances with SwiftUI lists indicating the best practices?
Thanks for your help !