SwiftData For Beginners: How To Build A To-Do List App In SwiftUI | #1

Поділитися
Вставка
  • Опубліковано 4 лип 2024
  • ⏭️ Next Video: SwiftData Relationships - • Swift Data Relationshi...
    SwiftData For Beginners: How To Build A To-Do List App In SwiftUI
    Build A To-Do List App using SwiftData (Swift Data Tutorials) - Free Course
    • SwiftData Todo List Ap...
    **********************************
    Timestamps:
    00:00 - Intro
    00:37 - 🚨Xcode 15 Warning
    01:26 - Creating A Model Entity in SwiftData
    02:58 - Registering Your Model in SwiftData
    03:44 - Quickly Building UI
    05:28 - How to Create in SwiftData
    08:35 - How to Fetch Data in SwiftData using Query in SwiftUI
    11:33 - How to delete data in SwiftData
    12:54 - Updating an item in SwiftData
    14:34 - Updating an item using a Form in SwiftData
    18:19 - Sorting & Filtering in SwiftData
    **********************************
    The SwiftUI team just dropped a madders, we've now got a CoreData alternative called SwiftData. In this SwiftData CRUD tutorial. We'll be looking at how to build a swiftui todo list app. To discover how swiftdata works. In this swift data app.
    This intro to SwiftData in this SwiftData tutorial will show you an introduction to SwiftData in SwiftUI, we'll look at how to tackle SwiftData CRUD operations, SwiftData filtering & SwiftData sorting. In this SwiftData beginner tutorial.
    🚨 One thing to keep in mind is that this video was recorded during WWDC week using Xcode 15 beta, some things may change and you may get some crashes sometimes
    And you can expect an updated video on my channel with everything related to SwiftData for this iOS todo app tutorial.
    **********************************
    Check Out My Courses 👨🏽‍🏫
    Enjoy my teaching style? Check out my other courses on my website that may interest you, they range from beginner to advanced topics within iOS development.
    Link to Website
    tunds.dev/#courses
    **********************************
    Join the crew 🤝
    Want to help support the channel? Become a member with the join link below and get access to exclusive badges and stickers, as well as other perks that are coming soon.
    Become a channel member
    www.youtube.com/@tundsdev/join
    Support in other ways 💕
    You can support me for free and help the channel grow so that I can continue to make the best iOS development content for you by liking, commenting, subscribing, and hitting the notification bell.
    All of this really helps my channel grow and allows me to keep on making content for you. If you’re interested in subscribing to the channel then you can do so with the link below.
    Subscribe to the tundsdev UA-cam channel
    ua-cam.com/users/tundsdev?su...
    **********************************
    Download Source Code
    Interested in looking at the source code? Then check out the GitHub Repo below
    github.com/tunds/youtube-cont...
    **********************************
    EditorKeys
    View Editor Keys Amazing Products with the link below and use the discount code for 10% off any product
    www.editorskeys.com/tundsdev
    Get a 10% Discount Code on any product with the code below
    TUNDSDEV
    See my keyboard cover in action with my review below 👇🏾
    • Increase Your Xcode Pr...
    **********************************
    RØDE Wireless Mic
    amzn.to/3D5qo3V
    RØDE SmartLavPlus Microphone
    amzn.to/3DtVUdG
    2021 Apple MacBook Pro (16-inch, Apple M1 Pro chip with 10‑core CPU and 16‑core GPU, 16GB RAM, 1TB SSD) - Space Grey
    amzn.to/3Drc2fH
    Apple Magic Keyboard with Numeric Keypad (Wireless, Rechargeable)
    amzn.to/3VUctXh
    Apple Magic Mouse
    amzn.to/3sqXSoM
    Secretlab TITAN 2020 Charcoal Blue Gaming Chair
    amzn.to/3D2jVXI
    ErgoFoam Ergonomic Foot Rest for Under Desk
    amzn.to/3srJOLM
    Lumbar Support Pillow
    amzn.to/3eXVfrg
    Macbook Stand for Apple Macbook and All Notebooks
    amzn.to/3DqG7vR
    Portable Chair Green Screen Background
    amzn.to/3gG62GU
    **********************************
    #iosdev #iosdevelopment #swift #swiftlanguage #xcode #appdevelopment #mobileappdevelopment #iosappdevelopment #appdeveloper #iosprogramming #iosengineer #appdevelopmenttips #iosdevelopmenttips #swiftui

КОМЕНТАРІ • 172

  • @tundsdev
    @tundsdev  11 місяців тому +7

    🚨Xcode Update🚨
    At 21:08 starting from Xcode 15 Beta 5, when sorting items you now need to include the root in the keypath too, so update the sort parameter to look like this.
    @Query(sort: \ToDoItem.timestamp) private var items: [ToDoItem]
    If you're having issues wtih the SwiftUI Previews I'd recommend watching my video in this course that shows you how to handle working with SwiftUI Previews & SwiftData down below!
    ua-cam.com/video/jCC3yuc5MUI/v-deo.html

    • @tundsdev
      @tundsdev  10 місяців тому +6

      Also when working with filters you need to specify the type too below is an example
      @Query(
      filter: #Predicate { $0.isCompleted == false }
      ) private var items: [ToDoItem]
      A combination of the two would look like this
      @Query(
      filter: #Predicate {$0.isCompleted == false},
      sort: \ToDoItem.timestamp
      ) private var items: [ToDoItem]

    • @keegan8176
      @keegan8176 9 місяців тому

      Thank you !! 😅spent a while stuck on this and couldve just opened the comments @@tundsdev 🤦‍♂

    • @dibjr
      @dibjr 7 місяців тому

      In the release Version 15.0.1 (15A507) the root is no longer required.

  • @chukwumaugonabo1045
    @chukwumaugonabo1045 Місяць тому

    Good stuff!

  • @ColeDano
    @ColeDano Рік тому

    Lovely stuff Tunds!

  • @ShawnChristopher10101
    @ShawnChristopher10101 11 місяців тому +3

    Thanks for the video. Getting into Swift now from a C#/React/Angular and this makes sense. Going to check out your other videos as I like your teaching style....and no, the fingers and trolley are cool ways to connect with people.

    • @tundsdev
      @tundsdev  11 місяців тому

      Glad it was helpful!

  • @danielaupont9468
    @danielaupont9468 Рік тому

    Great video! Can’t wait to try this out 🔥

  • @DezDoesMTB
    @DezDoesMTB Місяць тому +1

    Love the Deep Dish Swift shirt!!

  • @profgallaugher
    @profgallaugher Рік тому +3

    Great work. You do such good work. Swift on!

  • @julius00007
    @julius00007 Рік тому

    The best content as usual. 👏🏽

  • @meet071
    @meet071 Рік тому +2

    Smooth and clear video. Cheers 🥂

  • @user-ic3ie4vm9m
    @user-ic3ie4vm9m Рік тому +2

    Thank you so much for this video! I'm completely new to data persistence and to iOS development in general, so I found it super helpful.

    • @tundsdev
      @tundsdev  Рік тому

      Glad you enjoyed it 🤝

  • @jimmason4723
    @jimmason4723 Рік тому

    Brilliant mate, thanks for showing this.

  • @michanierebinski1423
    @michanierebinski1423 Рік тому +1

    Thanks for the vid. Quick and fun tutorial

    • @tundsdev
      @tundsdev  Рік тому +1

      Glad you enjoyed this 👌🏾

  • @TheBishopOfBarton
    @TheBishopOfBarton 11 місяців тому +1

    Great video - really well explained. Thanks man.

    • @tundsdev
      @tundsdev  11 місяців тому

      Glad you enjoyed it!

  • @danuff
    @danuff Рік тому +1

    Thanks for the video!

    • @tundsdev
      @tundsdev  Рік тому

      Thank you for watching 🤝

  • @sxmiotb2834
    @sxmiotb2834 Рік тому +1

    I love you man. Thank you so much

  • @wqlu3115
    @wqlu3115 Місяць тому +1

    thanks man, it’s very helpful!

  • @SiamakAshrafi
    @SiamakAshrafi Рік тому +1

    Great explanation ... Thanks!

  • @julianjpg
    @julianjpg 4 місяці тому +1

    You are awesome man! Thanks for saying my day!!! Wait a minute…. Ma hol coding life!! 👏🏾👏🏾👏🏾👏🏾👏🏾👏🏾

  • @ratatata6611
    @ratatata6611 9 днів тому

    Subbed!

  • @pgong415
    @pgong415 11 місяців тому +1

    Thanks for your efforts to show how to use SwiftData to build a ToDo app, where essential concepts and techniques are demonstrated. Great! You really help me sort out one of my problems - how to update items in SwiftData without using the trump merge policy. and I found the solution is so easy. Yes, of course because of beta version, the updating view can not be easily previewed, i believe the apple engineers can get it sorted asap before the official version is released. Bravo!

    • @tundsdev
      @tundsdev  11 місяців тому

      Glad you enjoyed it !

  • @evangelosspyromilios5994
    @evangelosspyromilios5994 Рік тому +5

    Thanks for the video mate! Having spent hours and hours to learn CoreData is simply amazes me how easy things are now with SwiftData! A 'part 2' of the video could include how to make relationships between models ;-)

    • @tundsdev
      @tundsdev  Рік тому +2

      Thanks and lol that is Part 2, the only thing deleting items with relationships crashes a lot at the moment, and i don't want to give y'all an half asses video so I hope they resolve this so that I can give you the best possible vid. Make sure you checking out the playlist since i'll be releasing a ton of videos about this topic on there as this app starts to grow 🤝

    • @tundsdev
      @tundsdev  11 місяців тому +1

      Here is the vid, explaining relationships btw 👀
      ua-cam.com/video/_QMalUGTM4E/v-deo.htmlsi=NRPtyNTXkH9M3lre

  • @nylelevi750
    @nylelevi750 Рік тому +1

    Can't believe the difference between CoreData and SwiftData. Thanks for the vid!

    • @tundsdev
      @tundsdev  Рік тому

      Glad you enjoyed it 👌🏾

  • @Itchster
    @Itchster Рік тому +1

    Great tutorial and a starting point to tinker with Swift data.
    It's just a shame you can't appreciate the divine taste of a Bounty!
    😆

    • @tundsdev
      @tundsdev  Рік тому

      Thanks, glad you enjoyed the vid & bounty’s aint it at all 😂

  • @qianqian888
    @qianqian888 10 місяців тому +1

    thank you~

    • @tundsdev
      @tundsdev  10 місяців тому

      Thank you for watching 👌🏾

  • @abdouett3676
    @abdouett3676 Рік тому +1

    Thank you for the video! To format a code to multiple lines, it’s actually possible scan the desired code > Right clic > Refractor > Format to multiple lines.

    • @tundsdev
      @tundsdev  Рік тому

      Glad you enjoyed the video👌🏾

    • @chezchezchezchez
      @chezchezchezchez 10 місяців тому

      @@tundsdev but did you enjoy his tip? Lol.

  • @chrisjackson9733
    @chrisjackson9733 Рік тому +1

    Another great video! Was wondering if you were planning on any videos overviewing Swift Macros. I think I have a general understanding but could use a clearer explanation. How are they different from property wrappers and/or packages?

    • @tundsdev
      @tundsdev  Рік тому +1

      Great suggestion, i’ll take a look into it for you 👌🏾

  • @m3zish
    @m3zish Рік тому +1

    Thanks for the video, very well explained. Not the first one I see, but the more I see, the more information I get :) Seems you have part 2 already planned, I have ideas for part 3 and maybe 4 and 5 lol :) I have an app that is using Core Data, and I could simplify it if I were to use SwiftData instead, but I haven't figured out how to "migrate" the data from Core Data to SwiftDate. I made several attempts, nothing worked, so a video showing how to migrate from one to another WITHOUT losing any data would be great! Another video would be about sharing SwiftData between iPhone main app and Watch companion app. I tried too, but it always crashes, not sure if I'm doing it wrong or if Xcode beta is unstable. Lastly: I haven't found much information on iCloud storing of the information and syncing with other devices/OSs, that would be another video to consider :) Thank again for the information so far :)

    • @tundsdev
      @tundsdev  Рік тому

      Thanks, all good suggestions. So some i have planned content for, others will be part of a paid course. So just keep your eyes peeled 👀

  • @alenkei1994
    @alenkei1994 Рік тому

    Thanks for the video! Would love a tutorial on using SwiftData to cache data from an API call and display it in case the user is offline; this would also help to reduce unnecessary API calls.

    • @tundsdev
      @tundsdev  Рік тому +1

      I’ve already written a script 👀
      It’ll feature a timed cache, but you can easily tweak it to handle offline connectivity

  • @ridholmes
    @ridholmes Рік тому

    Thank, Tunds!

    • @tundsdev
      @tundsdev  Рік тому

      No, thank you for watching 🫂

  • @solidenix
    @solidenix 6 місяців тому

    Great Video !
    Question, what would you change if you wanted to add additional criteria for sorting ? for example to sort by completed AND by timestamp?

  • @aerospaceexportsincorporat2753
    @aerospaceexportsincorporat2753 10 місяців тому +1

    Great video, thank you for sharing. Any chance in the future you could teach on how to add a “Select All” feature to this app to allow for deleting multiple ToDos at once? Again, well done!

    • @tundsdev
      @tundsdev  10 місяців тому

      Thanks & yh i’ll consider it 👌🏾

  • @millie6781
    @millie6781 8 місяців тому

    Bounty is so good thoughhhh😛(my favourite!!!) as much your video is helpful. Thank you for this amazing and well explained video☺

    • @tundsdev
      @tundsdev  8 місяців тому

      Glad you enjoyed the video 👌🏾

  • @iLoveAppl3947
    @iLoveAppl3947 4 місяці тому

    very good bruder

    • @tundsdev
      @tundsdev  4 місяці тому

      Nice one brudda

  • @alejmc
    @alejmc 11 місяців тому +1

    Just 9mins in but have subbed already, as someone that’s quite in diapers regarding SwiftUI and the surrounding Apple Frameworks this is quite concise and very well explained.
    I wonder if it is still alright to peek into CoreData (I also know nothing about it) since SwiftData will probably won’t be backported to previous iOS versions?
    I had started 100 Days of SwiftUI and one of the main things is “to not get distracted with too many things” but I guess WWDC23 and the new frameworks deserve a pause on that.
    Nevertheless, thanks for this… and for the chuckles too along the way 😅

    • @tundsdev
      @tundsdev  11 місяців тому +1

      Thanks and if you’re interested in Core Data in SwiftUI. Then I actually have a video that covers this. That may interest you
      Build Your Own Contacts App!!! | Core Data SwiftUI Tutorial
      ua-cam.com/video/rTXkGCg58w0/v-deo.html

    • @alejmc
      @alejmc 11 місяців тому +1

      @@tundsdev Thanks a lot, actually was just going to edit my own message as by the end of the video you had mentioned exactly that (the ailments of making comments without finishing the thing, my bad).
      Cheers once again.

  • @ChileMamaLC
    @ChileMamaLC 6 місяців тому +1

    What a great t-shirt! How might folks get an updated version of this for themselves I wonder? ;)

    • @tundsdev
      @tundsdev  6 місяців тому

      By attending one of my fave conferences 👀

  • @SettingUpTheChairs
    @SettingUpTheChairs Рік тому +1

    Awesome vid! Is there a way to have the data sync with the apple watch using SwiftData?

    • @tundsdev
      @tundsdev  Рік тому

      Thanks & yh you’ll probs want to look into using app groups to pass data between different targets 👌🏾

  • @cloftis130
    @cloftis130 Рік тому +1

    As always great video explaining a complicated topic. I do have a question…What is the key combination you use at about 17:03 mark to get the .sheet stub to change so that onDismiss is just in the closure? Thanks again Tunds.

    • @tundsdev
      @tundsdev  Рік тому

      Thanks & tbh I didn’t use a special key combination, I just hit enter 😅

    • @cloftis130
      @cloftis130 Рік тому +1

      @@tundsdev Cool. I didn't realize it was that simple to get the code completion to get rid of some of the options. That'll save some time. Keep up the good work.

  • @ampsonic
    @ampsonic 11 місяців тому +2

    How did you "collapse" the HStack to give yourself more room? That looks handy!

    • @tundsdev
      @tundsdev  11 місяців тому

      It’s a feature in Xcode called code folding, you have to turn it on via your preferences 👌🏾

  • @gmjelle
    @gmjelle 11 місяців тому

    Hi @tundsev, did you manage to make a model both @Model and Codable at the same time?

    • @tundsdev
      @tundsdev  11 місяців тому +1

      Yep, its coming out this sunday 👌🏾

  • @MarvelousLXVII
    @MarvelousLXVII 11 місяців тому

    Very nice video. Is there a way to create a query with predicates on the fly i.e. someone choosing what field to search-by?

    • @tundsdev
      @tundsdev  11 місяців тому

      Thanks & at this moment in time no. But if there is a way in the final release then i’ll do an updated video 👌🏾

    • @MarvelousLXVII
      @MarvelousLXVII 11 місяців тому

      @@tundsdev I just saw this in the docs--I think it's pretty much what I was thinking about.
      let simpleFood = #Predicate { recipe in
      recipe.ingredients.count < 3
      }

  • @benjaminanic7899
    @benjaminanic7899 8 місяців тому

    Do you have any videos on developing an app with the open ai GPT API?

    • @tundsdev
      @tundsdev  8 місяців тому

      Nope not atm no

  • @juanfrancisco9039
    @juanfrancisco9039 Рік тому +4

    Very nice video. Could you show how to prepopulate a database with SwiftData and use this data into relationships?

    • @tundsdev
      @tundsdev  Рік тому +2

      Great suggestion, I’ll look into it👌🏾

    • @marclutke1900
      @marclutke1900 Рік тому +2

      Firebase with Authentication would be great. 😅

    • @tundsdev
      @tundsdev  Рік тому

      Already in the works, but do you have anything specific you’d like to see? 👀

    • @marclutke1900
      @marclutke1900 Рік тому +1

      @@tundsdev it also would be great to have CRUD operations in it. Because in SwiftData we’re switching from structs to classes and the behavior is different when I was testing it.

  • @Bankai3474
    @Bankai3474 Рік тому

    In the WWDC keynote about making an app with SwiftData they used the @Bindable and they were able to save directly to the object, I tried doing the same but it doesn't like that for the Preview Window because the Bindable object (the object you're trying to persist) isn't initialized. Do you know anything about that?

    • @tundsdev
      @tundsdev  Рік тому +1

      So i actually have a video planned bout working with the new Preview macro & SwiftData coming out pretty soon to show you how to tackle this 👌🏾

  • @ViktorEvil
    @ViktorEvil Рік тому

    is it possible to have multiple sort options? on the @Query at the same time i.e I want to sort by name but if they are the same then use the time

    • @tundsdev
      @tundsdev  Рік тому +1

      So at the moment in time nope, it's not possible since you can only define a keypath on a property and sorting direction. If you wanted to do that you'd be better off copying what i did with my filter logic in this video so it can dynamically filter and sort the data or file a feedback with Apple so they can add this an improvement.

  • @jlock4545
    @jlock4545 9 місяців тому

    Hi Also get errors when I update the ContentView about 9:50 into the video. please help

    • @tundsdev
      @tundsdev  9 місяців тому

      Hey, you’ll need to be a bit more specific what errors are you getting?

  • @evroad
    @evroad 8 місяців тому

    Looks like a good example for Swift Data, however I've got an error I can't get around. At about 7:40 in the CreateView file on line 14 is @State private var item = ToDoItem(). I get an error "Missing argument for parameter 'backingData' in call" Thoughts? Thanks.

    • @tundsdev
      @tundsdev  8 місяців тому

      If you look at 2:15 have you forgot to add the default values to the initialiser?
      So when you create an instance of the the todo it doesn’t expect you to set every single param i.e title, timestamp, isCritical, isCompleted etc.
      This is what i think the problem is you’re facing

    • @evroad
      @evroad 8 місяців тому +1

      @@tundsdev That's it, Thanks!! Now I'll see if I can get a little further along tonight!

  • @SlakySlaky
    @SlakySlaky Рік тому

    Hello!
    How do we write unit tests for SwiftData?

    • @tundsdev
      @tundsdev  Рік тому +1

      This will be part of a paid course i’m working on, i still need to research/look into it

  • @sameershaik9110
    @sameershaik9110 24 дні тому

    How do i get ur code from github?

  • @haydgately2109
    @haydgately2109 Рік тому

    What is the best approach for waiting to see if the insert was correct before moving to a new screen, when there is no async/await for SwiftData? :) Thanks

    • @tundsdev
      @tundsdev  Рік тому

      Not too sure on you mean by the insert being correct? As soon as you insert it’ll be in memory so the new changes will be there and automatically persisted (as long as autosave is enabled) so when you go to the next screen the object should be there already

    • @haydgately2109
      @haydgately2109 Рік тому

      @@tundsdev hi sorry I meant success, not correct. So you do insert, but show a loading indicator whilst it does it, but also show and error if it fails? Great video! Any chance there could be a follow up syncing to cloudkit? 😇

    • @tundsdev
      @tundsdev  Рік тому

      So with swiftdata inserts are so instant you probs wouldn’t even need a spinner tbh. And cloudkit will be part of my paid course 👌🏾

  • @vanylaskywalker
    @vanylaskywalker Рік тому

    I've been using structs extensively.. because it was recommended to use codable structs instead of classes.. now do I have to switch everything to classes? Struct just went out of trend?

    • @tundsdev
      @tundsdev  Рік тому

      Apple recommends using classes in all of their sample code, probably because of the changes they’re made with the new Observation framework. For Models with SwiftData i’d stick to using classes 👌🏾

  • @chezchezchezchez
    @chezchezchezchez 10 місяців тому

    Would someone help me with the logic of deleting an item in the details view.
    I’m talking about my code, not his code.
    When I delete in the main view, it’s fine. But obviously, in the detail view, when you delete the item, you’re working with, the controls can’t update, because there’s no item any longer.
    It deletes fine, but then I get an error. What I really want, is to delete it, and go back to the main view. But it doesn’t work. I know about dismiss, and that works (when I’m not deleting an item)
    I can’t get deleted, and dismissed to work together without an error.
    Thanks so much

    • @tundsdev
      @tundsdev  10 місяців тому +1

      Hey, so when you call the dismiss function right after delete. What error are you getting? This should work which is weird

    • @chezchezchezchez
      @chezchezchezchez 10 місяців тому

      @@tundsdev Thanks for getting back to me.
      I’m at work now. I’ll edit this text with the error message when I get home.
      Wait a sec. I’m a NOOb.
      I don’t remember seeing an error.
      I think it went back to the “main” view and it was just blank screen.
      Anyway I’ll get back to you.
      I’m not good at seeing errors in the list at bottom, yet.

    • @chezchezchezchez
      @chezchezchezchez 10 місяців тому

      @@tundsdev
      Ok I made a YT vid for ya explaining it a bit:
      ua-cam.com/video/kggOPPMKmVs/v-deo.html

  • @allenwixted1992
    @allenwixted1992 7 місяців тому +1

    At 7:14 I get a crash when adding the model and container. "Failed to find a currently active container" comes up in the preview. Any ideas?

    • @tundsdev
      @tundsdev  7 місяців тому

      Have you set the modelContainer in the Previews? If not then you'll more than likely see this crash

    • @allenwixted1992
      @allenwixted1992 7 місяців тому

      @@tundsdev yeah that was my first thought also. Funnily, it works from the content view when pulling up the sheet, I can see the create a task view perfectly, but not via the create view itself

    • @dibjr
      @dibjr 7 місяців тому

      @@allenwixted1992 I have the same issue running Xcode 15.0.1, crashes in ModelContainer.swift, failed to find a currently active container for ToDoItem. It runs ok in the simulator. It just crashes in the preview.

  • @stanleyhuang2186
    @stanleyhuang2186 Рік тому

    is "TodoItem with @Model" still a class ?
    I saw you use @State.
    I am confused why it doesn't use @StateObject.

    • @tundsdev
      @tundsdev  Рік тому

      Reason why is because @Model is built ontop of the new @Observable macro which is only meant to be used with @State.
      It’s part of the new SwiftUI data flow coming in iOS 17 that works with classes for observing data. I’ll have a video out for it pretty soon 👌🏾

  • @celicagirls
    @celicagirls 3 місяці тому

    Hi at 7:14 i get a preview crash even after adding the model container has anything been updated since this was made thanks.

    • @tundsdev
      @tundsdev  3 місяці тому

      Hi, this video was created during the beta. So there are a few changes around previews but everything else is still valid. One thing I would say is in the course you should look at the previews videos in it. And check out the sample code too in the description box 👌🏾
      SwiftData Todo List App | SwiftData For Beginners | SwiftData In SwiftUI
      ua-cam.com/play/PLvUWi5tdh92wZ5_iDMcBpenwTgFNan9T7.html

    • @celicagirls
      @celicagirls 3 місяці тому

      @@tundsdev Hi thanks will have a look at the previews videos much appreciated.

    • @tundsdev
      @tundsdev  3 місяці тому

      Also pls check out the starter and final source code for the course especially the previews folder 👌🏾
      github.com/tunds/youtube-content-2023

  • @stephenjennings2256
    @stephenjennings2256 10 місяців тому

    At this point would your bother learning core data or focus your energy in swiftdata?

    • @tundsdev
      @tundsdev  10 місяців тому +1

      I do think SwiftData is great, there’s still a few things that need ironing out. But my personal apps will all be using SwiftData going forward, WWDC24 is where I think it will be standard imo

  • @janstehlik3939
    @janstehlik3939 Рік тому

    Question: if we create a @Model class with a custom struct as an attribute, and save this as an array (e.g. class Item { var details: [Detail] } ) how is this saved in the underlying Core Data? It sounds like an equivalent of a one-to-many relationship, but without a second object; which I can't wrap my head around

    • @tundsdev
      @tundsdev  Рік тому

      Based on what you’re saying you’d possibly want to create a relationship between the two, using the relationship macro.
      I actually have a script/vid planned to show this, but currently in the first Xcode 15 bets deletes with relationships crash at lot.
      Once that is more stable I will release the vid, since it goes over one to many relationships 👌🏾

    • @janstehlik3939
      @janstehlik3939 Рік тому

      @@tundsdev I understand we can create a one-to-many relationship using a macro. My question is more about the new composite attributes, and whether they can replace a to-many relationship. Another example: class Car { var wheels: [Wheel] }, where Wheel is not another class, but a struct, and saved (somehow) as a composite attribute.

    • @tundsdev
      @tundsdev  Рік тому +1

      Ahhhh ok got you, so I saw this in the modelling your data video. I’m not too sure on the benefits/differences something i’d have to explore and checkout myself since its still early days
      I have a project where i can mess around with your example let me play around & find out for you? 👀

    • @janstehlik3939
      @janstehlik3939 Рік тому

      @@tundsdev that would be amazing, thanks! IF this is possible, it could be important, because we could replace a to-many relationship and therefore avoid faulting a second table into memory when fetching. This could result in significant performance gains for large datasets.

    • @tundsdev
      @tundsdev  Рік тому

      So i’ve not tested it yet. But been compiling code in my brain 😅
      And I think what would happen is that you’d basically have the data associated with the model. But I do think the model would have to be a codable, since you’re not defining another model. My guess would be SwiftData would just flatten it and save it.
      I think examples like where a to do could have a category you probs wouldn’t want to do this since you’d want a model where you can query all categories.
      If you had them all associated with a model as an array of structs you’d have to get all the to do’s and then the categories in them you can see where the problem is starting. So those relationships help with maintaining data integrity.
      I do think it would be useful for things like configurations i.e lets say a to do had a set of configurations like priority, tags, location to trigger etc. Since you dont need to query stuff like this.
      These are my thoughts/thinking

  • @franksolleveld2909
    @franksolleveld2909 Рік тому

    Have you noticed the Missing argument for parameter 'backingData' in call whenever making the @State property in 6:38? I imported SwiftData and declared a modelContainer in the Preview. Unsure what's happening

    • @tundsdev
      @tundsdev  Рік тому

      I have not noticed that error with the Xcode15 beta. Maybe give the project a clean, clear derived data, also in the description box is the complete project so you can compare.
      But i’ve not used that backingData property, since i have a init where i set the default params for each property so I can just create an empty to do 👌🏾

    • @franksolleveld2909
      @franksolleveld2909 Рік тому +1

      @@tundsdev yeah i noticed your init aswell. Filed a bug report for it, will remove it if I noticed something i did that caused it 😂

    • @tundsdev
      @tundsdev  Рік тому

      I’m curious if my final project has the same issues on your machine 👀

    • @franksolleveld2909
      @franksolleveld2909 Рік тому +1

      Apparently I had to make it private ;-)

    • @thilotech
      @thilotech 11 місяців тому

      @@tundsdev Just out of curiosity since I faced the same issue when not having default values, why does this happen? Is this intentional?

  • @sergpryimachuk
    @sergpryimachuk Рік тому

    C'mon, I like Bounty! 😆

    • @tundsdev
      @tundsdev  Рік тому

      *Shakes head in disappointment*

  • @kenturnbull9679
    @kenturnbull9679 10 місяців тому

    👍👍 + 2 jam butties

    • @tundsdev
      @tundsdev  10 місяців тому

      You're a man of good taste 🤝

  • @highlyevolved4977
    @highlyevolved4977 7 місяців тому

    How dare you diss bounty!! Unsub nowwww

  • @hannahn9464
    @hannahn9464 7 місяців тому

    specific

  • @LebenWerden
    @LebenWerden 3 місяці тому

    Hello, what about
    @StateObject
    @ObservedObject
    @Binding
    @EnvironmentObject
    @Published
    Better avoiding them?

  • @iwy2th
    @iwy2th Рік тому +1

    thank !!!From Viet Nam !

    • @tundsdev
      @tundsdev  Рік тому

      Thank you, glad you enjoyed it 👌🏾

  • @maartenborsje
    @maartenborsje 9 місяців тому +1

    Error: Cannot infer type of closure parameter '$0' without a type annotation
    Can be resolved by changing:
    @Query(
    filter: #Predicate { $0.isCompleted == false },
    sort: \.timestamp,
    order: .reverse
    ) private var items: [ToDoItem]
    to
    @Query(
    filter: #Predicate { $0.isCompleted == false },
    sort: \.timestamp,
    order: .reverse
    ) private var items: [ToDoItem]

    • @ColeDano
      @ColeDano 9 місяців тому

      Thanks Maarten

    • @tundsdev
      @tundsdev  9 місяців тому

      👌🏾should also be in the pinned comments too

  • @teakodo
    @teakodo 4 місяці тому

    For those getting
    Cannot infer type of closure parameter '$0' without a type annotation
    you need to add or in the video's case
    @Query(
    filter: #Predicate { $0.isCompleted == false },
    sort: \.timeStamp,
    order: .forward
    ) private var items: [Item]

    • @tundsdev
      @tundsdev  4 місяці тому +1

      I added a pinned comment & this to the description explaining this btw, it was a change made during one of the xcode betas 😅

    • @teakodo
      @teakodo 3 місяці тому

      @@tundsdev thank you ! didn't see my bad

  • @kenturnbull9679
    @kenturnbull9679 10 місяців тому

    Good Tutorial. NavBarTitle not showing up on edit view. Small thing...$0.isCompleted == false ; Simpler ==> !$0.iscompleted.

    • @tundsdev
      @tundsdev  10 місяців тому

      Thanks & I actually prefer explicitly stating the condition its way more readable imo 👌🏾

    • @tundsdev
      @tundsdev  10 місяців тому

      Also with the Title bar not showing up, I just forgot to add the NavigationStack. You can easily add that in if you want too 👌🏾

    • @kenturnbull9679
      @kenturnbull9679 10 місяців тому

      Too many years of Oracle for me. Now I have to get used to this way of doing things...although SwiftData is a lot better than CoreData@@tundsdev

  • @jlock4545
    @jlock4545 9 місяців тому

    Hi Great work! I am using XcodeI 15.0 and I am having an issue on the #Preview when I add the '.modelContainer(for: ToDoItem.self)' in the CreatView file?
    The error Xcode gives me is this:
    MyToDos crashed due to fatalError in ModelContainer.swift at line 144.
    failed to find a currently active container for ToDoItem
    Does anyone know how to fix this please or is it a bug?
    Thanks

    • @tundsdev
      @tundsdev  9 місяців тому

      Hmm that should work, can you check out the free source files to compare what may be different and also make the changes that I pinned in the comments section on this video too.
      github.com/tunds/youtube-content-2023/tree/main/SwiftData%20Is%20Way%20Easier%20Than%20CoreData%20😇%20%7C%20Build%20A%20Todo%20app%20using%20SwiftData
      I also have another video which you should check out which goes over a better way of handling SwiftUI previews with SwiftData
      ua-cam.com/video/jCC3yuc5MUI/v-deo.html
      Hope this helps

    • @romanyefimets454
      @romanyefimets454 3 місяці тому

      i seem to have the same error, anyone figure it out?

    • @tundsdev
      @tundsdev  3 місяці тому

      Hey you’ll 100% want to check out my video that goes over working with SwiftData and the Previews which covers an even better way of handling this the link is above ☝🏾

    • @romanyefimets454
      @romanyefimets454 3 місяці тому

      @@tundsdevnot sure which video you are referring to, i see links to the playlist.

    • @tundsdev
      @tundsdev  3 місяці тому

      @romanyefimets454
      How To Use SwiftData with Preview | SwiftData Tutorial | #10
      ua-cam.com/video/jCC3yuc5MUI/v-deo.html