6. Swift Data Many to Many relationships
HTML-код
- Опубликовано: 19 июл 2024
- This is the 6th video in the SwiftData series where I am building an app to track books you want to read, are currently reading or have read.
In this video, I will be introducing a many to many relationship so that we an create a list of genres and associate our books with one or more of these.
We will be looking at what a one to many relationship is and what you need to look out for when creating and deleting genres from a book or the genres array itself.
If you want to support my work, you can buy me a coffee :)
ko-fi.com/stewartlynch
Table of Contents:
0:00 Introduction
1:10 Many to Many Relationships
1:42 The Genre Model
9:41 The GenreView
17:43 The NewGenreView
25:48 The GenreStackView
29:54 Deleting Genres
Starter Project Files:
github.com/StewartLynch/MyBoo...
Completed Project:
github.com/StewartLynch/MyBoo...
Hex Color Extension
www.ditto.live/blog/swift-hex...
All videos in this section
SwiftData: Lightweight Migrations
• 4. SwiftData Lightweig...
SwiftData: One To Many Relationships
• 5. Swift Data One to M...
SwiftData: Many to Many Relationships
• 6. Swift Data Many to ...
Recommended Resources:
BigMountain Studio Books
SwiftUI Views Mastery
www.bigmountainstudio.com/vie...
SwiftUI 5 Book Bundle
www.bigmountainstudio.com/boo...
Combine Mastery in SwiftUI
www.bigmountainstudio.com/com...
Core Data Mastery in SwiftUI
www.bigmountainstudio.com/cor...
SwiftUI Animations Mastery
www.bigmountainstudio.com/ani...
AppCoda Books
Beginning iOS 16 Programming with Swift (SwiftUI + UIKit)
gumroad.com/a/646790611/WihuX
Beginning iOS 16 Programming with Swift (SwiftUI + UIKit) - Starter
gumroad.com/a/646790611/mOzKq
Mastering SwiftUI 4 + Swift Programming for iOS 16 - Professional
gumroad.com/a/646790611/gjPBw
Mastering SwiftUI 4 - Starter
gumroad.com/a/646790611/TyNEz
Other References:
Stewart Lynch's RUclips Channel:
/ @stewartlynch
Stewart Lynch on Mastodon:
iosdev.space/@StewartLynch
Stewart Lynch On Threads:
@StewartLynch
Stewart Lynch on X:
x.com/StewartLynch
Stewart Lynch on LinkedIn
/ stewartlynch - Наука
This is one of the BEST series on SwiftData out there and certainly the most comprehensive one! Thanks a million, Stewart!
Glad you think so! I am planning another one that is mostly MapKit, but it also uses SwiftData
Stewart, great video as usual!
Infinite gratitude for all lessons Stewart 🙏💯 for top explanation and top self giving…💯♨️ special for colors 🙌 Beautiful and Nice Christmas 🎄 for you and your family ❤ Wish you Health and long life 💯🙏
Thanks again Stewart. A realistic example, that can be adopted/adapted for many applications. One view that could be added is a list of genres, each displaying the books that belong to it. That’s where you could also delete a genre, and see the full effect that that action would have, rather than scan the book list visually.
Yes, a lot more can be done with this app, but I needed to stop somewhere. I might do an extra video later on that adds on a few other things like editing genres as well.
This is one of my favorite series Stewart! It is so well done. I have many projects with Core Data, and SwiftData is so much more approachable. Thanks for a fantastic series!
One question, will you be covering modifying and existing Core Data project to SwiftData? Thanks again!
Not in this series but I might add a video on the topic next year.
Thanks!
Thank you Andrew
Thanks Stewart for this video. I do not seem to be able to find the link to the extensions mentioned in the video. Do I need to change my glasses ?
Thanks Lars. I have added it to the description now
These are great. And plans to cover CloudKit and previews together?
Cloudkit is coming before Christmas
@@StewartLynch amazing! 🤩
@@StewartLynch since adding CloudKit my previews crash. Looking forward to seeing how it’s done!
I have had no issues with my implementation as you will see.
@@StewartLynch fantastic. Am sure I missed something basic. Appreciate it a lot!
Stewart, I am very enthusiastic about following your tutorials on RUclips. I have a running project (just for fun) in which I have provided the auxiliary table Z_1GENRES with additional fields so that I can provide each many to many connection with additional properties. In my existing project with Vapor, I could also do this by simply defining a class that reflects this auxiliary table. Do you have a tip on how to do this with SwiftData?
How did you highlight the if/else block and just enclose it in a group? I always cut the highlighted block, create the group, then past it inside.
Just highlight the code and type { or and of the enclosure brackets like ( or [
@@StewartLynch can't believe I never knew that! Thanks!
Great video. In it you say that you want to specify the inverse relationship between \Genre.books and \Book.genres, but you don't really say why you want to do that?
I don’t recall if I ever used this now, but you can specify the inverse to that the relationship can be inferred both ways giving you the ability to perform methods affecting models in both directions
Thank you for the video dear friend.
Alas, SwiftData is still not ready for real life, for example you can never filter your books by tag, you will get an error if you try to do that. That's just the way Apple is...
You can filter in memory and not use a query
Like the pace of the video, where he pauses like he's coding/thinking along side us. Compared to someone just copy code from another screen.
Thanks. That is what I am doing.
love your content, but the audio quality needs some attention. getting crackles and distortion.
I think you will find that in my more recent videos the audio is better. Just remember the content is free.
@@StewartLynch Oh yes, really appreciate the high-quality content itself. Thanks much.
Thanks!
Thank you
Thanks!
Thank YOu
Thanks!
Thank you