SwiftData in SwiftUI (Part 1)

<h2>Model Container</h2> <ul> <li>An object that manages an app&rsquo;s schema and model storage configuration.</li> <li>Model Container is set in&nbsp;<strong>WindowGroup</strong>. We can pass multiple data models over there.</li> </ul> <pre> @main struct SwiftData_ExampleApp: App { var body: some Scene { WindowGroup { NavigationStack { UserList() } } .modelContainer(for: [User.self, Company.self]) } }</pre> <h1>ModelContext</h1> <ul> <li>An object that enables you to fetch, insert, and delete models, and save any changes to disk.</li> <li>Everything in SwiftData happens with model context.</li> <li>It is basically like view context in CoreData.</li> </ul> <pre> @Environment(\.modelContext) private var modelContext</pre> <h1>Query</h1> <ul> <li>Use&nbsp;<code>@Query</code>&nbsp;in your SwiftUI views to fetch data.</li> <li>SwiftData and SwiftUI work together to provide live updates to your views when the underlying data changes, with no need to manually refresh the results.</li> <li>You can add&nbsp;<strong>predicate</strong>&nbsp;to the query to filter the elements,&nbsp;<strong>sort</strong>&nbsp;the query, set the&nbsp;<strong>order</strong>- whether to sort in forward or reverse order and set&nbsp;<strong>animation</strong>&nbsp;for user interface changes that result from changes to the fetched results.</li> </ul> <p><a href="https://medium.com/@priya_talreja/swiftdata-in-swiftui-part-1-18919ce2612"><strong>Click Here</strong></a></p>