
Master SwiftData declarative persistence by building a movie app that saves, fetches, updates, and deletes movies and reviews using CRUD operations, and demonstrates one-to-many relationships and many-to-many relationships with actors.
Meet the prerequisites for SwiftData: install Xcode 15 beta or newer and iOS 17, have Swift language knowledge, and know this course focuses on SwiftData rather than Swift basics.
Download exercise files for each lecture to access code, such as saving a movie, and view the full project by downloading the last lecture file.
Learn how iOS 17+ simplifies ui state management by consolidating options into state, environment, and bindable, with new initializers and environments that provide values directly.
Demonstrate @State private local state in a SwiftUI view, updating a count via a button, displaying changes, and using binding for toggles and the upcoming Bindable to modify parent state.
Explore how the Bindable property wrapper lets a child view update its parent by binding a room light. SwiftData's observable macro then triggers content view color changes.
Explains using the environment wrapper to share global state across SwiftUI views, injecting at the root and accessing it in content, room, and cabin.
Define a movie model with Swift Data, input title and year in a form, save via the model context to the SQLite database, and test in the simulator.
Fetch all movies with a SwiftData query, display them in a movie list screen, and add new movies via a modal sheet with a toolbar in a SwiftUI app.
Enable sql debugging in Swift Data to view insert, select, update, and delete queries in the output window, and learn to pass Core Data style flags for debugging during development.
Learn to implement a movie list view with swiftdata, use on delete to remove a movie via the model context, persist changes to sqlite, and verify deletion.
Create a movie detail screen to update an existing movie by populating fields from the selected movie, validating input, and saving changes to the persistent context.
Understand one-to-many relationships with examples like a movie and its many reviews. Also see that many reviews can belong to a single movie, and view the relationship from both sides.
Create a review model and configure a one-to-many relationship with movie using SwiftData, with subject and body, review belonging to a movie, and cascade delete for SQLite persistence.
Create and save movie reviews with a subject and description on an add review screen, backed by SwiftData for persistence and validation.
Build a review list view to display all reviews for a movie, using a ForEach in a VStack to show each review’s subject and description in the movie details screen.
Implement deleting a review in review list view using the on delete modifier, delete review function with an index set, and the model context to perform deletion and save changes.
Fixes deleting reviews in SwiftData by passing the movie object to the review list view, shows a no-reviews view when empty, and refreshes the parent screen after deletion.
Define an actor model and establish a many-to-many relationship with movies, configure inverse properties, decorate with the model macro, and enable creating or selecting actors when adding a movie.
Add a new actor via a sheet in the movie list, enter a name, and use the model context to insert and save the actor in SQLite for later display.
Fetch all actors with a query property wrapper, sort by name, and display them in an actor list view alongside the movie list using a SwiftUI list.
Learn to implement an actor selection view in SwiftUI with checkboxes and binding to a selected actors set, saving a new movie and balancing actor-movie relationships.
Display all actors for a movie by introducing an actor cell view that shows each actor’s name and their movies using actor.movies.map, with a content unavailable view when empty.
Enable actors to select and manage their movies in a SwiftUI app. Use a movie selection view, actor detail screen with navigation, and binding to reflect changes with SwiftData.
Learn how swift data queries fetch and sort data, apply filters with predicate macros, and build dynamic, multi-criteria queries for movies and actors.
Implement enum based sheets to replace multiple state variables by using an identifiable enum and an active sheet binding to present add movie, add actor, and filter screens as modals.
Build a filter selection screen in SwiftUI to search movies by title using a binding enum, presented as a modal, feeding results to the movie list.
Learn to filter movies by title using a dynamic query in SwiftData, passing a bindable filter option to the movie list view and applying a contains predicate.
Use the @Transient macro to expose not stored movie counts, such as reviews and actors, in the user interface by declaring transient properties and displaying them under the movie title.
Learn to filter movies by the number of reviews by selecting a reviews count option, update the filter UI, and use reviews.count in predicates to query persisted data correctly.
Add a new actors count filter in the SwiftData SwiftUI app, binding the value, defaulting to one, and update the query to require at least three actors.
Learn how versioning, or migration, preserves data when a model changes, using lightweight migrations to rename title to name and custom migrations to enforce data integrity and unique constraints.
Apply a custom migration to enforce a unique constraint on movie names. Create schema versions, migrate from V1 to V2, and update duplicates with a uuid while preserving existing data.
Perform a lightweight migration by renaming the movie title to name, using the original name feature to preserve data across schema versions from v2 to v3.
Explore the starter project updated for Xcode 15, including the new relationship delete rule, and download the code to implement genre enum, persistence, and genre filtering in the movie app.
Implement a codable, iterable, identifiable genre enum with integer raw values, extend it for display titles, and integrate it into the movie model to display and persist genres.
Display and select a movie genre with a segmented picker, bind it to the movie via a genre enum, add actors, and persist data to memory or the database.
Learn to filter movies by genre in a SwiftData SwiftUI app using a genre picker and enum, but resolve predicate limits by switching to a genre id for comparison.
Switch to using a genre ID for filtering with SwiftData, update predicates to compare integers, and centralize filter state in the movie list screen.
Lift filter state into a shared filter selection config outside the screen, including title, reviews, and genre, and bind it to the movie list view to persist and reset filters.
Discover how to store transformable types like colors in a database using the swift data framework, then save, retrieve, and display multiple room colors in a SwiftUI app.
Implement a room model with the model macro, add a transformable color property, and implement a color value transformer to convert color to and from data for persistence.
Implement UI color transformer to convert UI color to data via archiving for a color property. Conform to the value transformer protocol and implement transform and reverseTransform, handling errors.
Set up a user interface with a name text field and a color selector, using bindings to pass selected color to content view and prepare for SwiftData SQLite persistence.
Persist a room to the database using swift data by registering a UIColor value transformer, initializing the model container, and saving a room’s name and color through the model context.
Display all rooms and their colors using a Swift data query, showing each room name alongside a color rectangle, with color persistence via a transformable ui color value.
Explore the spend smart budgeting app built with swift data, focusing on unit testing, with budget categories, transactions, and model-led logic to enable testable code and prepare for end-to-end tests.
Set up a unit testing target and a mock in-memory container to test throwing an error when adding a duplicate budget category title using SwiftData model context.
Write unit tests in SwiftData to verify budget totals and remaining amounts by adding transactions to a budget category, using fixtures, main actor context, and in-memory data.
Set up end-to-end UI tests by adding a UI testing bundle, initializing the app, and using launch arguments with a real database for clean test resets.
Write end-to-end tests for budget category and transaction flow using a page object pattern, validating add and remove actions on budget list screens and detail screens.
Discover the power of SwiftData as you dive into the world of data persistence in Swift. This course provides an introduction to SwiftData, covering essential concepts such as declarative code, one-to-many relationships, many-to-many relationships, persistence, and querying. You will learn how to effortlessly persist data using SwiftData's intuitive approach. Explore the intricacies of establishing and managing relationships, enabling you to organize and associate data effectively. Unlock the ability to query and filter data with regular Swift code, unleashing the full potential of SwiftData. By the end of this course, you'll have a solid foundation in SwiftData, equipped with the skills to develop robust, data-driven applications with ease. Join now and master the art of data persistence and querying in Swift using SwiftData!
Who is this course for:
- Swift developers who want to expand their knowledge and skills in data persistence.
- iOS app developers who want to learn how to effectively store and retrieve data in Swift applications.
- Beginner developers looking to understand the fundamentals of data persistence and querying in Swift using declarative code.
- Experienced developers who want to enhance their data handling capabilities and learn advanced techniques for querying and filtering data.
- Developers interested in integrating data persistence seamlessly with SwiftUI for building robust and data-driven user interfaces.
- Individuals seeking to develop efficient and scalable applications that rely on one-to-many relationships between data entities.
- Programmers who want to leverage the power of SwiftData to streamline their development process and improve the efficiency of data management tasks.
What will students learn in this course:
- The fundamentals of data persistence in Swift using SwiftData.
- How to use declarative code to easily persist data in their applications.
- Techniques for establishing and managing one-to-many relationships between data entities.
- Strategies for efficiently querying and filtering data using regular Swift code.
- Integration of SwiftData seamlessly with SwiftUI for building data-driven user interfaces.
- Real-world application of SwiftData concepts through the development of a sample project.
- The skills and knowledge necessary to confidently develop robust and scalable applications with SwiftData.