iOS 15: One-to-many relationships with @FetchRequest and SwiftUI - Core Data SwiftUI Tutorial 7/7

Поделиться
HTML-код
  • Опубликовано: 13 окт 2024
  • Download the completed project here: github.com/two...
    Other parts in Project 12:
    Introduction: www.hackingwit...
    1. Why does \.self work for ForEach?: • iOS 15: Why does \.sel...
    2. Creating NSManagedObject subclasses: • iOS 15: Creating NSMan...
    3. Conditional saving of NSManagedObjectContext: • iOS 15: Conditional sa...
    4. Ensuring Core Data objects are unique using constraints: • iOS 15: Ensuring Core ...
    5. Filtering @FetchRequest using NSPredicate: • iOS 15: Filtering @Fet...
    6. Dynamically filtering @FetchRequest with SwiftUI: • iOS 15: Dynamically fi...
    7. One-to-many relationships with Core Data, SwiftUI, and @FetchRequest
    Challenges: This video
    Wrap up and challenges: www.hackingwit...
    You can find the full set of videos, along with transcriptions, challenges, tests, and more, in my free 100 Days of SwiftUI course: www.hackingwit...
    Watch the full 100 Days of SwiftUI playlist here: • Hacking with iOS: Swif...

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

  • @sxlx
    @sxlx 2 года назад +14

    One man has many dogs.
    Many dogs have one man.

  • @LeoJunquera
    @LeoJunquera Год назад +4

    Another great video. Do you have an example of a core data and a form supporting a many-to-many relationship?

  • @LeoJunquera
    @LeoJunquera Год назад +2

    Great tutorial. Do you have a many to many example? One where you might have to keep additional in the intermediate table? Like Recipe/Ingredient with an intermediate table for amount, or User/Rating/Restaurant, etc.

  • @yanhao-li
    @yanhao-li 2 года назад +9

    Love the dogs!

  • @cliffspencer
    @cliffspencer 2 года назад +3

    Paul, shouldn't those convenience properties be called unwrapped* as you are actually unwrapping the optional?

    • @twostraws
      @twostraws  2 года назад +9

      I went back and forward on the naming a few times, because although I'm unwrapping them I'm not *just* unwrapping them - it's not like a force unwrap, but instead some wrapper code that provides a default value. I've used unwrapped* elsewhere a few times, so it's not like I'm firmly committed to the choice 🙂

    • @mutualrespect4411
      @mutualrespect4411 2 года назад +1

      @@twostraws I went with unwrappedWrapped

  • @tommy9576
    @tommy9576 2 года назад +1

    Such a great tutorial, you helped me so often!

  • @midlifematt
    @midlifematt 2 года назад

    I am in the mood for candy now 🍬… those dogs though, wonderful 😊 Love the videos 👍🏻

  • @АльфредГордан
    @АльфредГордан Год назад

    OMG. this video is mind-blowing

  • @hamidehsheikh2619
    @hamidehsheikh2619 Год назад

    Such a great tutorial, and you are the best teacher. Thank you so much🥰

  • @isthorify
    @isthorify 2 года назад +1

    Thx for this. I followed this tutorial using swift playground on the iPad. It works fine, but is it possible to set Contraints for Entity manually, not using Xcode ?

  • @uniquecrafter4432
    @uniquecrafter4432 2 года назад +2

    If I want to store URLs and UUIDs in Core Data, what should I nil coalesce to when creating those computed properties? A new empty URL instance (i.e URL(fileWithPath: "") and a new UUID() instance respectively?

  • @tiIIus
    @tiIIus 2 года назад +1

    Thank you, that's such great tutorial!

  • @beanberg
    @beanberg Год назад

    Thanks so much for your tutorial! It helped me lots

  • @AndyJMacLeod
    @AndyJMacLeod 2 года назад

    Why did Paul call those variables wrappedShortname (etc) rather than unwrappedShortname? Thanks.

  • @LeoJunquera
    @LeoJunquera Год назад

    Couldn't you have the classes automatically created and create an extension class for the object and still use Codegen = class definition?

  • @sirpoohbehr4793
    @sirpoohbehr4793 2 года назад

    Insanely helpful tyvm :D

  • @kafran
    @kafran 2 года назад

    Wouldn't it be better to put the wrapped properties as an Extension in another file so it doesn't get rewritten?

  • @seungjunlee00
    @seungjunlee00 2 года назад

    Thanks you sooo much foir this awesome great video!

  • @RoustamManookian
    @RoustamManookian Год назад

    Hi, how to fetch only the Countries without the relationship entities?

  • @ec92009y
    @ec92009y Год назад

    How many treats do they get everyday?

  • @devsmond
    @devsmond 2 года назад

    How can I create data and display it when the app starts, without having to click the button first?

    • @nabs
      @nabs 2 года назад +2

      Anywhere where your code already runs without an explicit interaction (like a button press) would work. An example would be the ContentView’s initializer, or in CoreDataProjectApp before ContentView is initialized. Just remember to remove that code after it runs once, otherwise you’d be attempting to create and save that data on each run

    • @devsmond
      @devsmond 2 года назад

      ​@@nabs Thank you for this! I tried messing around with the initializer before asking this question but I can't get a full grasp on how to use it with my data model.

  • @DaveyonMayne-ok
    @DaveyonMayne-ok 2 года назад

    Hola. Could you make a video on how to update/delete an entity?

    • @MoAdel92
      @MoAdel92 2 года назад

      He did before

    • @MoAdel92
      @MoAdel92 2 года назад +1

      Revise bookworm series

    • @xingguohuang4487
      @xingguohuang4487 Год назад

      @@MoAdel92Could you please share the link? I looked everywhere but couldn’t find it.😂

  • @梁非凡-h6i
    @梁非凡-h6i 2 года назад

    constraints failed to work in Xcode Version 14.1 beta (14B5024h) sometimes, I added constraints for shortName but I can still see a bunch of entries with the same short name, I even downloaded your project 12 from github and directly run on my mac, still no luck. But previously it worked perfectly for singers with same names, really strange.

    • @iurii513
      @iurii513 Год назад

      Same thing here. Did you get a solution?

    • @JonSweeney26
      @JonSweeney26 Год назад

      ​@@iurii513 Be sure to update the Persistence file generated in Xcode 14.0+. I added the self.container.viewContext.mergePolicy = NSMergePolicy.mergeByPropertyObjectTrump to line 55, after the container...MergesChangesFromParent = true in the initializer.

    • @aleixplanasguibas
      @aleixplanasguibas Год назад

      @@JonSweeney26 what do you mean to line 55? It isn't working for me and I can't find any information regardless the merge policy getting old. Could you be more specific? Thanks!!

    • @maxmaxmaxmaxmaxmaxmaxmaxmax1
      @maxmaxmaxmaxmaxmaxmaxmaxmax1 Год назад

      To your DataController file, add the following code after your closing brace for container.loadPersistentStores (probably line 15)
      self.container.viewContext.mergePolicy = NSMergePolicy.mergeByPropertyObjectTrump

    • @jlleee
      @jlleee Год назад

      I thought I had the same but I missed the part where he added try? moc.save() at the end

  • @udesai2011
    @udesai2011 2 года назад

    Is there a working code for download available?

  • @Alshafi
    @Alshafi 2 года назад

    how to clean all the errors and warnings?

  • @DavidNitzscheBell
    @DavidNitzscheBell 2 года назад

    Well, well, well....Who would have thought that I'd learn something about the origin of candy bars in a video about SwiftUI???? I was all ready to "correct" you about the origin of Mars, Twix and KitKat (I'm from the US and, of course, *everything* was invented in the US, right? ) but life has taught me to look things up first. And, lo and behold, invented in UK!!! So, at least I can blame the UK for being the US's origin story for fascination with junk food. ;)

  • @dannytong2010
    @dannytong2010 2 года назад +2

    Power of Hungry Dogs lol 🤣