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
  • НаукаНаука

Комментарии • 42

  • @dmacharo
    @dmacharo 6 месяцев назад +3

    This is one of the BEST series on SwiftData out there and certainly the most comprehensive one! Thanks a million, Stewart!

    • @StewartLynch
      @StewartLynch  6 месяцев назад +1

      Glad you think so! I am planning another one that is mostly MapKit, but it also uses SwiftData

  • @dibjr
    @dibjr 7 месяцев назад

    Stewart, great video as usual!

  • @andrejkling3886
    @andrejkling3886 7 месяцев назад +1

    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 💯🙏

  • @TomWGiles
    @TomWGiles 9 месяцев назад

    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.

    • @StewartLynch
      @StewartLynch  9 месяцев назад +1

      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.

  • @holycrosscv
    @holycrosscv 7 месяцев назад

    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!

    • @StewartLynch
      @StewartLynch  7 месяцев назад

      Not in this series but I might add a video on the topic next year.

  • @AndrewDChristie
    @AndrewDChristie 4 месяца назад

    Thanks!

  • @larschristiansen3136
    @larschristiansen3136 8 месяцев назад

    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 ?

    • @StewartLynch
      @StewartLynch  8 месяцев назад

      Thanks Lars. I have added it to the description now

  • @allenwixted1992
    @allenwixted1992 7 месяцев назад +1

    These are great. And plans to cover CloudKit and previews together?

    • @StewartLynch
      @StewartLynch  7 месяцев назад +1

      Cloudkit is coming before Christmas

    • @allenwixted1992
      @allenwixted1992 7 месяцев назад

      @@StewartLynch amazing! 🤩

    • @allenwixted1992
      @allenwixted1992 7 месяцев назад +1

      @@StewartLynch since adding CloudKit my previews crash. Looking forward to seeing how it’s done!

    • @StewartLynch
      @StewartLynch  7 месяцев назад

      I have had no issues with my implementation as you will see.

    • @allenwixted1992
      @allenwixted1992 7 месяцев назад

      @@StewartLynch fantastic. Am sure I missed something basic. Appreciate it a lot!

  • @peterbien2879
    @peterbien2879 7 месяцев назад

    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?

  • @timothycbryant
    @timothycbryant 3 месяца назад

    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.

    • @StewartLynch
      @StewartLynch  3 месяца назад

      Just highlight the code and type { or and of the enclosure brackets like ( or [

    • @timothycbryant
      @timothycbryant 3 месяца назад

      @@StewartLynch can't believe I never knew that! Thanks!

  • @robertdavis7262
    @robertdavis7262 2 месяца назад

    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?

    • @StewartLynch
      @StewartLynch  2 месяца назад

      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

  • @MrKoksirk
    @MrKoksirk 3 месяца назад

    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...

    • @StewartLynch
      @StewartLynch  3 месяца назад

      You can filter in memory and not use a query

  • @seccat
    @seccat 3 месяца назад

    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.

    • @StewartLynch
      @StewartLynch  3 месяца назад

      Thanks. That is what I am doing.

  • @Dudadius
    @Dudadius 4 месяца назад

    love your content, but the audio quality needs some attention. getting crackles and distortion.

    • @StewartLynch
      @StewartLynch  4 месяца назад

      I think you will find that in my more recent videos the audio is better. Just remember the content is free.

    • @Dudadius
      @Dudadius 4 месяца назад

      @@StewartLynch Oh yes, really appreciate the high-quality content itself. Thanks much.

  • @AndrewDChristie
    @AndrewDChristie 6 месяцев назад

    Thanks!

  • @AndrewDChristie
    @AndrewDChristie 6 месяцев назад

    Thanks!

  • @AndrewDChristie
    @AndrewDChristie 6 месяцев назад

    Thanks!