Back to Browse

SwiftData and the @Observable Macro: A Practical Guide

346 views
Premiered Apr 27, 2025
9:02

๐Ÿš€ SwiftUI E-commerce Masterclass: Build a Full-Stack App in 2025! ๐Ÿ›๏ธ Link to Complete 26+ hour Course and Source Code: https://patrickwaga.gumroad.com/l/gkjaw ๐ŸŽ“ First 12 hours of the complete 26-hour project available for free on this channel! ๐Ÿ‘‰๐Ÿฟhttps://youtu.be/56C5JvvwB7E Unlock cleaner, more manageable #SwiftData code in your SwiftUI apps! While powerful, integrating SwiftData seamlessly with the modern @Observable macro isn't always straightforward. This practical guide shows you exactly how to do it. In the video we dive into structuring your SwiftData implementation using an Observable Manager pattern. We'll take a real-world example app featuring a many-to-many relationship (Students and Courses) and refactor it step-by-step. In this video, you'll learn: Why managing SwiftData state with @Observable can be beneficial (especially for testing or specific architectures like MVC/MVVM). How to create a dedicated Manager class using @Observable and @MainActor. The right way to inject the SwiftData ModelContext into your manager. How to implement CRUD (Create, Read, Update, Delete) operations within the manager. How to refactor your SwiftUI views to interact with the SDManager instead of directly manipulating the context. Practical tips for saving data and ensuring your UI updates correctly. By the end, you'll have a clear pattern for organizing your SwiftData logic, leading to cleaner, more maintainable, and potentially more testable code. Source Code: https://github.com/OdongoWaga/Many2Many

Download

1 formats

Video Formats

360pmp49.1 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

SwiftData and the @Observable Macro: A Practical Guide | NatokHD