Fetching data
To integrate with SwiftUI, we use the @Query annotation to fetch data and display it into SwiftUI views.
Here’s an example:
@Query var posts: [Post]
var body: some View {
      List(posts) { recipe in
            NavigationLink(post.name, destination: PostView(post))
      }
}			The @Query annotation links the posts variable to the views so that SwiftData fetches them from the underlying database.
This has the effect of refreshing the views utilizing posts whenever the underlying data changes, without any action being necessary in the code.
 
                                             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
     
         
                 
                 
                 
                 
                 
                 
                 
                 
                