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

  Рет қаралды 23,330

tundsdev

tundsdev

Күн бұрын

⏭️ 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 KZfaq channel
kzfaq.info?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

Пікірлер: 173
@tundsdev
@tundsdev Жыл бұрын
🚨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! kzfaq.info/get/bejne/oKlzZtymyJuxhX0.html
@tundsdev
@tundsdev 11 ай бұрын
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 10 ай бұрын
Thank you !! 😅spent a while stuck on this and couldve just opened the comments @@tundsdev 🤦‍♂
@dibjr
@dibjr 8 ай бұрын
In the release Version 15.0.1 (15A507) the root is no longer required.
@nileshjdarji
@nileshjdarji 22 күн бұрын
It's great that you are pasting code to save time but it would be nice if you quickly go over the code that you pasted so we don't have to pause the video and read the code. Because sometimes there is more code to fit in the screen and we cannot see everything at one time. Just a suggestion. I am enjoying this series.👍
@ShawnChristopher10101
@ShawnChristopher10101 Жыл бұрын
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 Жыл бұрын
Glad it was helpful!
@user-ic3ie4vm9m
@user-ic3ie4vm9m Жыл бұрын
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 🤝
@danielaupont9468
@danielaupont9468 Жыл бұрын
Great video! Can’t wait to try this out 🔥
@tundsdev
@tundsdev Жыл бұрын
Thanks my man 🫂
@DezDoesMTB
@DezDoesMTB 2 ай бұрын
Love the Deep Dish Swift shirt!!
@chukwumaugonabo1045
@chukwumaugonabo1045 2 ай бұрын
Good stuff!
@ColeDano
@ColeDano Жыл бұрын
Lovely stuff Tunds!
@tundsdev
@tundsdev Жыл бұрын
Thanks ❤️
@profgallaugher
@profgallaugher Жыл бұрын
Great work. You do such good work. Swift on!
@tundsdev
@tundsdev Жыл бұрын
Thanks 🫂
@evangelosspyromilios5994
@evangelosspyromilios5994 Жыл бұрын
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 Жыл бұрын
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 Жыл бұрын
Here is the vid, explaining relationships btw 👀 kzfaq.info/get/bejne/lbd9lM-GrLqxZHk.htmlsi=NRPtyNTXkH9M3lre
@jimmason4723
@jimmason4723 Жыл бұрын
Brilliant mate, thanks for showing this.
@tundsdev
@tundsdev Жыл бұрын
Thanks ❤️
@michanierebinski1423
@michanierebinski1423 Жыл бұрын
Thanks for the vid. Quick and fun tutorial
@tundsdev
@tundsdev Жыл бұрын
Glad you enjoyed this 👌🏾
@julius00007
@julius00007 Жыл бұрын
The best content as usual. 👏🏽
@tundsdev
@tundsdev Жыл бұрын
Thanks ❤️
@pgong415
@pgong415 Жыл бұрын
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 Жыл бұрын
Glad you enjoyed it !
@meet071
@meet071 Жыл бұрын
Smooth and clear video. Cheers 🥂
@tundsdev
@tundsdev Жыл бұрын
Thanks 🫂
@sxmiotb2834
@sxmiotb2834 Жыл бұрын
I love you man. Thank you so much
@tundsdev
@tundsdev Жыл бұрын
Appriciate it 🫂
@TheBishopOfBarton
@TheBishopOfBarton Жыл бұрын
Great video - really well explained. Thanks man.
@tundsdev
@tundsdev Жыл бұрын
Glad you enjoyed it!
@ratatata6611
@ratatata6611 Ай бұрын
Subbed!
@julianjpg
@julianjpg 5 ай бұрын
You are awesome man! Thanks for saying my day!!! Wait a minute…. Ma hol coding life!! 👏🏾👏🏾👏🏾👏🏾👏🏾👏🏾
@tundsdev
@tundsdev 5 ай бұрын
Any time!
@nylelevi750
@nylelevi750 Жыл бұрын
Can't believe the difference between CoreData and SwiftData. Thanks for the vid!
@tundsdev
@tundsdev Жыл бұрын
Glad you enjoyed it 👌🏾
@wqlu3115
@wqlu3115 2 ай бұрын
thanks man, it’s very helpful!
@tundsdev
@tundsdev 2 ай бұрын
Glad it helped!
@abdouett3676
@abdouett3676 Жыл бұрын
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 11 ай бұрын
@@tundsdev but did you enjoy his tip? Lol.
@danuff
@danuff Жыл бұрын
Thanks for the video!
@tundsdev
@tundsdev Жыл бұрын
Thank you for watching 🤝
@chrisjackson9733
@chrisjackson9733 Жыл бұрын
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 Жыл бұрын
Great suggestion, i’ll take a look into it for you 👌🏾
@solidenix
@solidenix 7 ай бұрын
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 11 ай бұрын
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 11 ай бұрын
Thanks & yh i’ll consider it 👌🏾
@Itchster
@Itchster Жыл бұрын
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 😂
@m3zish
@m3zish Жыл бұрын
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 Жыл бұрын
I’ve already written a script 👀 It’ll feature a timed cache, but you can easily tweak it to handle offline connectivity
@alejmc
@alejmc Жыл бұрын
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 Жыл бұрын
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 kzfaq.info/get/bejne/qLqInqp0zJucp2Q.html
@alejmc
@alejmc Жыл бұрын
@@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.
@SiamakAshrafi
@SiamakAshrafi Жыл бұрын
Great explanation ... Thanks!
@tundsdev
@tundsdev Жыл бұрын
Thanks 👌🏾
@ridholmes
@ridholmes Жыл бұрын
Thank, Tunds!
@tundsdev
@tundsdev Жыл бұрын
No, thank you for watching 🫂
@ChileMamaLC
@ChileMamaLC 7 ай бұрын
What a great t-shirt! How might folks get an updated version of this for themselves I wonder? ;)
@tundsdev
@tundsdev 7 ай бұрын
By attending one of my fave conferences 👀
@SettingUpTheChairs
@SettingUpTheChairs Жыл бұрын
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 👌🏾
@millie6781
@millie6781 9 ай бұрын
Bounty is so good thoughhhh😛(my favourite!!!) as much your video is helpful. Thank you for this amazing and well explained video☺
@tundsdev
@tundsdev 9 ай бұрын
Glad you enjoyed the video 👌🏾
@cloftis130
@cloftis130 Жыл бұрын
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 Жыл бұрын
@@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.
@qianqian888
@qianqian888 11 ай бұрын
thank you~
@tundsdev
@tundsdev 11 ай бұрын
Thank you for watching 👌🏾
@ampsonic
@ampsonic Жыл бұрын
How did you "collapse" the HStack to give yourself more room? That looks handy!
@tundsdev
@tundsdev Жыл бұрын
It’s a feature in Xcode called code folding, you have to turn it on via your preferences 👌🏾
@gmjelle
@gmjelle Жыл бұрын
Hi @tundsev, did you manage to make a model both @Model and Codable at the same time?
@tundsdev
@tundsdev Жыл бұрын
Yep, its coming out this sunday 👌🏾
@MarvelousLXVII
@MarvelousLXVII Жыл бұрын
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 Жыл бұрын
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 Жыл бұрын
@@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 }
@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 Жыл бұрын
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.
@iLoveAppl3947
@iLoveAppl3947 5 ай бұрын
very good bruder
@tundsdev
@tundsdev 5 ай бұрын
Nice one brudda
@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 Жыл бұрын
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 👌🏾
@benjaminanic7899
@benjaminanic7899 9 ай бұрын
Do you have any videos on developing an app with the open ai GPT API?
@tundsdev
@tundsdev 9 ай бұрын
Nope not atm no
@juanfrancisco9039
@juanfrancisco9039 Жыл бұрын
Very nice video. Could you show how to prepopulate a database with SwiftData and use this data into relationships?
@tundsdev
@tundsdev Жыл бұрын
Great suggestion, I’ll look into it👌🏾
@marclutke1900
@marclutke1900 Жыл бұрын
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 Жыл бұрын
@@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.
@evroad
@evroad 9 ай бұрын
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 9 ай бұрын
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 9 ай бұрын
@@tundsdev That's it, Thanks!! Now I'll see if I can get a little further along tonight!
@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 👌🏾
@sameershaik9110
@sameershaik9110 Ай бұрын
How do i get ur code from github?
@chezchezchezchez
@chezchezchezchez 11 ай бұрын
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 11 ай бұрын
Hey, so when you call the dismiss function right after delete. What error are you getting? This should work which is weird
@chezchezchezchez
@chezchezchezchez 11 ай бұрын
@@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 11 ай бұрын
@@tundsdev Ok I made a YT vid for ya explaining it a bit: kzfaq.info/get/bejne/oc2XgrOBsrHRhqc.html
@jlock4545
@jlock4545 10 ай бұрын
Hi Also get errors when I update the ContentView about 9:50 into the video. please help
@tundsdev
@tundsdev 10 ай бұрын
Hey, you’ll need to be a bit more specific what errors are you getting?
@SlakySlaky
@SlakySlaky Жыл бұрын
Hello! How do we write unit tests for SwiftData?
@tundsdev
@tundsdev Жыл бұрын
This will be part of a paid course i’m working on, i still need to research/look into it
@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 👌🏾
@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 4 ай бұрын
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 4 ай бұрын
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 kzfaq.info/sun/PLvUWi5tdh92wZ5_iDMcBpenwTgFNan9T7
@celicagirls
@celicagirls 4 ай бұрын
@@tundsdev Hi thanks will have a look at the previews videos much appreciated.
@tundsdev
@tundsdev 4 ай бұрын
Also pls check out the starter and final source code for the course especially the previews folder 👌🏾 github.com/tunds/youtube-content-2023
@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 Жыл бұрын
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
@stephenjennings2256
@stephenjennings2256 11 ай бұрын
At this point would your bother learning core data or focus your energy in swiftdata?
@tundsdev
@tundsdev 11 ай бұрын
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
@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 Жыл бұрын
@@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 Жыл бұрын
Apparently I had to make it private ;-)
@thilotech
@thilotech Жыл бұрын
@@tundsdev Just out of curiosity since I faced the same issue when not having default values, why does this happen? Is this intentional?
@allenwixted1992
@allenwixted1992 8 ай бұрын
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 8 ай бұрын
Have you set the modelContainer in the Previews? If not then you'll more than likely see this crash
@allenwixted1992
@allenwixted1992 8 ай бұрын
@@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 8 ай бұрын
@@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.
@sergpryimachuk
@sergpryimachuk Жыл бұрын
C'mon, I like Bounty! 😆
@tundsdev
@tundsdev Жыл бұрын
*Shakes head in disappointment*
@kenturnbull9679
@kenturnbull9679 11 ай бұрын
👍👍 + 2 jam butties
@tundsdev
@tundsdev 11 ай бұрын
You're a man of good taste 🤝
@highlyevolved4977
@highlyevolved4977 8 ай бұрын
How dare you diss bounty!! Unsub nowwww
@hannahn9464
@hannahn9464 8 ай бұрын
specific
@LebenWerden
@LebenWerden 4 ай бұрын
Hello, what about @StateObject @ObservedObject @Binding @EnvironmentObject @Published Better avoiding them?
@maartenborsje
@maartenborsje 11 ай бұрын
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 10 ай бұрын
Thanks Maarten
@tundsdev
@tundsdev 10 ай бұрын
👌🏾should also be in the pinned comments too
@iwy2th
@iwy2th Жыл бұрын
thank !!!From Viet Nam !
@tundsdev
@tundsdev Жыл бұрын
Thank you, glad you enjoyed it 👌🏾
@kenturnbull9679
@kenturnbull9679 11 ай бұрын
Good Tutorial. NavBarTitle not showing up on edit view. Small thing...$0.isCompleted == false ; Simpler ==> !$0.iscompleted.
@tundsdev
@tundsdev 11 ай бұрын
Thanks & I actually prefer explicitly stating the condition its way more readable imo 👌🏾
@tundsdev
@tundsdev 11 ай бұрын
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 11 ай бұрын
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 10 ай бұрын
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 10 ай бұрын
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 kzfaq.info/get/bejne/oKlzZtymyJuxhX0.html Hope this helps
@romanyefimets454
@romanyefimets454 4 ай бұрын
i seem to have the same error, anyone figure it out?
@tundsdev
@tundsdev 4 ай бұрын
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 4 ай бұрын
@@tundsdevnot sure which video you are referring to, i see links to the playlist.
@tundsdev
@tundsdev 4 ай бұрын
@romanyefimets454 How To Use SwiftData with Preview | SwiftData Tutorial | #10 kzfaq.info/get/bejne/oKlzZtymyJuxhX0.html
@teakodo
@teakodo 5 ай бұрын
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 5 ай бұрын
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 5 ай бұрын
@@tundsdev thank you ! didn't see my bad
Swift Data Relationships 🚀 | SwiftData Tutorial | #2
26:52
Smart Sigma Kid #funny #sigma #memes
00:26
CRAZY GREAPA
Рет қаралды 6 МЛН
IQ Level: 10000
00:10
Younes Zarou
Рет қаралды 11 МЛН
Amazing weight loss transformation !! 😱😱
00:24
Tibo InShape
Рет қаралды 67 МЛН
86. Dragging UIView with Long Press Gesture - Learn Swift For Beginners
4:01
JPEG is Dying - And that's a bad thing
8:09
2kliksphilip
Рет қаралды 18 М.
BREAKING Chess Drama As Niemann Rips Into Magnus Carlsen
8:25
Epic Chess
Рет қаралды 51 М.
How To Save A Struct In SwiftData | SwiftData Tutorial | #14
7:19
Build a SwiftUI to-do app from scratch with Realm Crash Course
42:40
Not In 138 Years Have We Seen Chess Domination Like This
11:21
Epic Chess
Рет қаралды 44 М.
Smart Sigma Kid #funny #sigma #memes
00:26
CRAZY GREAPA
Рет қаралды 6 МЛН