[SwiftData] How to use @Query to get the first 7 elements in the list

Maybe I didn't find the relevant instructions.

In my code, I only want to get the first 7 elements.

At present, my code is as follows:

@Query(sort:\Record.date, order: .reverse) private var records:[Record]

But I wonder if once the number of records is large, will it affect the efficiency?

In View, it is enough for me to count the first 7 elements in records. What should I do?

Answered by Ming-Ryu in 813387022

This is a repeated question, and it has been answered in the link below. Another question

Accepted Answer

This is a repeated question, and it has been answered in the link below. Another question

[SwiftData] How to use @Query to get the first 7 elements in the list
 
 
Q