SwiftData by Example: iOS 17 & SwiftUI 5 — Part 11
<p>The Query macro holds a pivotal position within the SwiftData ecosystem, primarily serving as a cornerstone for data retrieval and processing. While we’ve utilized this macro to access books from the persistence store, our usage has been limited to basic scenarios thus far. Let’s dive deeper into the Query macro’s capabilities.</p>
<p>We will use GenreListView to explore Query macro. Notice that the Query macro we are using for Genre, fetches the data sorted by name.</p>
<pre>
@Query(sort: \Genre.name) private var genres: [Genre]</pre>
<p>But Query macro doesn’t need this parameter and can work without it as well.</p>
<pre>
@Query private var genres: [Genre]</pre>
<p>Let’s use first overload which takes FetchDescriptor as a parameter. The FetchDescriptor is a type that describes the criteria, sort order, and any additional configuration to use when performing a fetch.</p>
<p><a href="https://medium.com/devtechie/swiftdata-by-example-ios-17-swiftui-5-part-11-ee149beba4ff"><strong>Learn More</strong></a></p>