🚨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! ruclips.net/video/jCC3yuc5MUI/видео.html
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]
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.👍
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.
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.
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 ;-)
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 🤝
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!
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?
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!
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 😅
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 ruclips.net/video/rTXkGCg58w0/видео.html
@@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.
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 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.
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.
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 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.
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 :)
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
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
@@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 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
@@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.
@@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 }
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.
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
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 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.
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
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?
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 👌🏾
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.
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?
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
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 👌🏾
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 👌🏾
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
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 👌🏾
@@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.
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? 👀
@@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.
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
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 ruclips.net/p/PLvUWi5tdh92wZ5_iDMcBpenwTgFNan9T7
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]
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]
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
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 ruclips.net/video/jCC3yuc5MUI/видео.html Hope this helps
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 ☝🏾
🚨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!
ruclips.net/video/jCC3yuc5MUI/видео.html
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]
Thank you !! 😅spent a while stuck on this and couldve just opened the comments @@tundsdev 🤦♂
In the release Version 15.0.1 (15A507) the root is no longer required.
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.👍
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.
Glad you enjoyed the video👌🏾
@@tundsdev but did you enjoy his tip? Lol.
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.
Glad it was helpful!
Can't believe the difference between CoreData and SwiftData. Thanks for the vid!
Glad you enjoyed it 👌🏾
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 ;-)
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 🤝
Here is the vid, explaining relationships btw 👀
ruclips.net/video/_QMalUGTM4E/видео.htmlsi=NRPtyNTXkH9M3lre
Great work. You do such good work. Swift on!
Thanks 🫂
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!
Glad you enjoyed it !
You are awesome man! Thanks for saying my day!!! Wait a minute…. Ma hol coding life!! 👏🏾👏🏾👏🏾👏🏾👏🏾👏🏾
Any time!
How did you "collapse" the HStack to give yourself more room? That looks handy!
It’s a feature in Xcode called code folding, you have to turn it on via your preferences 👌🏾
Love the Deep Dish Swift shirt!!
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.
Glad you enjoyed it 🤝
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?
Smooth and clear video. Cheers 🥂
Thanks 🫂
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!
Thanks & yh i’ll consider it 👌🏾
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 😅
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
ruclips.net/video/rTXkGCg58w0/видео.html
@@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.
Awesome vid! Is there a way to have the data sync with the apple watch using SwiftData?
Thanks & yh you’ll probs want to look into using app groups to pass data between different targets 👌🏾
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?
Great suggestion, i’ll take a look into it for you 👌🏾
The best content as usual. 👏🏽
Thanks ❤️
Lovely stuff Tunds!
Thanks ❤️
Great video - really well explained. Thanks man.
Glad you enjoyed it!
Very nice video. Could you show how to prepopulate a database with SwiftData and use this data into relationships?
Great suggestion, I’ll look into it👌🏾
Firebase with Authentication would be great. 😅
Already in the works, but do you have anything specific you’d like to see? 👀
@@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.
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.
I’ve already written a script 👀
It’ll feature a timed cache, but you can easily tweak it to handle offline connectivity
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.
Thanks & tbh I didn’t use a special key combination, I just hit enter 😅
@@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.
thanks man, it’s very helpful!
Glad it helped!
What a great t-shirt! How might folks get an updated version of this for themselves I wonder? ;)
By attending one of my fave conferences 👀
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!
😆
Thanks, glad you enjoyed the vid & bounty’s aint it at all 😂
Great video! Can’t wait to try this out 🔥
Thanks my man 🫂
Thanks for the vid. Quick and fun tutorial
Glad you enjoyed this 👌🏾
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 :)
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 👀
How do i get ur code from github?
Good stuff!
Thanks for the video!
Thank you for watching 🤝
Brilliant mate, thanks for showing this.
Thanks ❤️
I love you man. Thank you so much
Appriciate it 🫂
Great explanation ... Thanks!
Thanks 👌🏾
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
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
@@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? 😇
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 👌🏾
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?
Have you set the modelContainer in the Previews? If not then you'll more than likely see this crash
@@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
@@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.
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?
Thanks & at this moment in time no. But if there is a way in the final release then i’ll do an updated video 👌🏾
@@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
}
Hi @tundsev, did you manage to make a model both @Model and Codable at the same time?
Yep, its coming out this sunday 👌🏾
Bounty is so good thoughhhh😛(my favourite!!!) as much your video is helpful. Thank you for this amazing and well explained video☺
Glad you enjoyed the video 👌🏾
thank you sooooo much!😀
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.
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
@@tundsdev That's it, Thanks!! Now I'll see if I can get a little further along tonight!
Do you have any videos on developing an app with the open ai GPT API?
Nope not atm no
Subbed!
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
Hey, so when you call the dismiss function right after delete. What error are you getting? This should work which is weird
@@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.
@@tundsdev
Ok I made a YT vid for ya explaining it a bit:
ruclips.net/video/kggOPPMKmVs/видео.html
At this point would your bother learning core data or focus your energy in swiftdata?
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
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?
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 👌🏾
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
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.
Hello!
How do we write unit tests for SwiftData?
This will be part of a paid course i’m working on, i still need to research/look into it
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?
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 👌🏾
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
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 👌🏾
@@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 😂
I’m curious if my final project has the same issues on your machine 👀
Apparently I had to make it private ;-)
@@tundsdev Just out of curiosity since I faced the same issue when not having default values, why does this happen? Is this intentional?
is "TodoItem with @Model" still a class ?
I saw you use @State.
I am confused why it doesn't use @StateObject.
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 👌🏾
Hi Also get errors when I update the ContentView about 9:50 into the video. please help
Hey, you’ll need to be a bit more specific what errors are you getting?
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
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 👌🏾
@@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.
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? 👀
@@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.
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
Hi at 7:14 i get a preview crash even after adding the model container has anything been updated since this was made thanks.
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
ruclips.net/p/PLvUWi5tdh92wZ5_iDMcBpenwTgFNan9T7
@@tundsdev Hi thanks will have a look at the previews videos much appreciated.
Also pls check out the starter and final source code for the course especially the previews folder 👌🏾
github.com/tunds/youtube-content-2023
thank you~
Thank you for watching 👌🏾
very good bruder
Nice one brudda
Thank, Tunds!
No, thank you for watching 🫂
C'mon, I like Bounty! 😆
*Shakes head in disappointment*
👍👍 + 2 jam butties
You're a man of good taste 🤝
How dare you diss bounty!! Unsub nowwww
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]
Thanks Maarten
👌🏾should also be in the pinned comments too
Hello, what about
@StateObject
@ObservedObject
@Binding
@EnvironmentObject
@Published
Better avoiding them?
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]
I added a pinned comment & this to the description explaining this btw, it was a change made during one of the xcode betas 😅
@@tundsdev thank you ! didn't see my bad
specific
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
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
ruclips.net/video/jCC3yuc5MUI/видео.html
Hope this helps
i seem to have the same error, anyone figure it out?
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 ☝🏾
@@tundsdevnot sure which video you are referring to, i see links to the playlist.
@romanyefimets454
How To Use SwiftData with Preview | SwiftData Tutorial | #10
ruclips.net/video/jCC3yuc5MUI/видео.html
Good Tutorial. NavBarTitle not showing up on edit view. Small thing...$0.isCompleted == false ; Simpler ==> !$0.iscompleted.
Thanks & I actually prefer explicitly stating the condition its way more readable imo 👌🏾
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 👌🏾
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
thank !!!From Viet Nam !
Thank you, glad you enjoyed it 👌🏾