You came in clutch many times ever since i started making my app a few weeks ago. Always had a video for whatever frustrating roadblock i was in. Really appreciate you sharing what you learned with everyone else, I could not fathom having to spend hours figuring this out on my own just by reading documentation. Thanks.
Great to hear you found this useful, I’d actually check out my newer video with improvements on how to filter data too 👌🏾 A Better Way To Add Dynamic Filtering In SwiftData | SwiftData Tutorial | #16 ruclips.net/video/V4kHAKmC53Y/видео.html
This is a great one! How would you go about hiding the search bar when there are no To-Dos yet? Since the .searchable modifier does not directly support conditional application, would you recommend going with a conditional view structure?
Fantastic video you made and great ways to have a searching bar . I have a question: if I accidentally delete the item, how do I restore it , or how do I make a query that filters all deleted items and show them on a view where i can restore the items that i want to ?
You can filter on date, but you have to do a lil bit of a trick which you can see here stackoverflow.com/questions/77143462/how-to-filter-by-current-date-using-swiftdata-and-query
We’re going places alright thanks to you 🙏 😂 just another great video ❤ Suggestion: vid no.4 Sync the app with iCloud 😬 no pressure. I don’t need it but it’s just a suggestion. 👋
Thanks so much for this series! It's really helpful! Just one thing, between video parts, I'm noticing some continuity issues. For example, at 1:12 I see there's code for .sheet, but I don't have that at all. I double-checked the Github repo and that also has what I have. Where did this new code come from? I've been following each video part very closely and did not see any modification to this part of the code in a prior part. Can you please explain or perhaps point to an updated Github repo? Thanks!
@@tundsdev Yes, I started the whole series from part 1 and have the sheet code. However, it's very different from what I have, and I didn't see any changes made to the code in the video.
Thanks, I cover this in the first vid of this course (link below) that shows you how to filter completed items but essentially you’d use a predicate on filter on the date that is in today Build A To Do List App using SwiftData (Swift Data Tutorials) ruclips.net/p/PLvUWi5tdh92wZ5_iDMcBpenwTgFNan9T7
@@tundsdev I followed that but got stuck at the last hurdle 😅 couldn't figure out what to put after '==' I had set a constant called 'today' to Date() and insert this but I kept getting 'Cannot use instance member 'today' within property initializer; property initializers run before 'self' is available' I'm still super noob so not sure what I'm doing wrong
Hey no worries, so the equal wont work cos that is comparing the actual date to now instead you want to check if a todo item is in today. Here’s a link with examples hopefully this helps 👌🏾 stackoverflow.com/questions/39345101/swift-check-if-a-timestamp-is-yesterday-today-tomorrow-or-x-days-ago
Just noticed that my filteredItems is returning ONLY Items and not Categories as well. Could it be the definition? Too Quick on the comment didn't watch long enough...sorry.
This works for one query on the dataset creating the List but how would filteredItems work when you section the list for Active and Completed items? I ended up in a continuous loop. I'm thinking a List to replace the the display of the two sections when searchquery is not empty and a list with the two sections showing when searchQuery is empty.
I would just have two ForEach’s & have two query macros that use the filter predicate to show completed & uncompleted. Then you can just have two sections 👌🏾
@@tundsdev Already have that so I don't use allItems Query, but filteredItems refers ONLY to AllItems(my name) hence my thinking to show a list of the filtered items (1 section) when searchQuery has content and two sections when searchQuery is empty. //MARK: - QUERIES @Query(sort:\ToDoItem.timestamp, order:.reverse) private var allItemsza: [ToDoItem] @Query(filter: #Predicate {!$0.isCompleted}, sort: [SortDescriptor(\ToDoItem.timestamp, order: .reverse)]) var activeToDo: [ToDoItem] @Query(filter: #Predicate {$0.isCompleted}, sort: [SortDescriptor(\ToDoItem.timestamp, order: .reverse)]) var completedToDo: [ToDoItem] var filteredItems: [ToDoItem] { if searchString.isEmpty { return allItemsza } let filteredItems = allItemsza.compactMap { item in let titleContainsQuery = item.title.range( of: searchString, options: .caseInsensitive) != nil return titleContainsQuery ? item : nil } return filteredItems }
I was wondering why the list was getting redrawn each time a simple computed property was changing, but it is because searchQuery is declared with @State
Firstly, thank for this! Secondly, are you sure this is the right way we should be filtering? As far as I can see -- and feel free to correct -- we are still fetching 100% of the database. And then, we're filtering those (possibly thousands) of entries. If you have, say a diary app, that's going to be a big DB hit after years of use. It seems to me that we need to be filtering at the query level, with a predicate. Regards.
Hey for a big dataset, i would actually tweak this approach. But for something simple like this it should be fine. I also have an upcoming paid course that will explore efficient queries but this is just something quick and easy. For bigger datasets i.e over 50k records it would be nice in the upcoming betas if Apple released a way to trigger/update the query & sorting kinda like how you can update the sort order with FetchRequest👌🏾
I am extremely enjoying your this series. Great Job. I learned some cool stuff.
Watched a few tutorials before I found this one. None of them clicked until this! Thank you, my friend!
You came in clutch many times ever since i started making my app a few weeks ago. Always had a video for whatever frustrating roadblock i was in. Really appreciate you sharing what you learned with everyone else, I could not fathom having to spend hours figuring this out on my own just by reading documentation. Thanks.
Great to hear you found this useful, I’d actually check out my newer video with improvements on how to filter data too 👌🏾
A Better Way To Add Dynamic Filtering In SwiftData | SwiftData Tutorial | #16
ruclips.net/video/V4kHAKmC53Y/видео.html
very good video, well explained and worked perfectly for my application... keep up the great work!
Glad it helped!, be sure to watch the rest of the vids in the playlist!
Best SwiftData tutorial on UTube
Thanks 🤝
This is a great one! How would you go about hiding the search bar when there are no To-Dos yet? Since the .searchable modifier does not directly support conditional application, would you recommend going with a conditional view structure?
Yh its not the best but yh you’d have to do that, also i have a even better filtering video coming out this sunday
You are the best man, really !
Great to hear, heads up I have an improvement coming soon of this video 👀
@@tundsdev keep up the good work 👍
Fantastic video you made and great ways to have a searching bar . I have a question: if I accidentally delete the item, how do I restore it , or how do I make a query that filters all deleted items and show them on a view where i can restore the items that i want to ?
Thanks and if you enable the undo manager I think you can undo changes that you’ve made on your persistant store
Looking forward to this!
Great to hear 👌🏾
LOVE your videos!! Can you filter on the Date?? I can not seem to right code for the comparable to give me all items due on one date.
You can filter on date, but you have to do a lil bit of a trick which you can see here
stackoverflow.com/questions/77143462/how-to-filter-by-current-date-using-swiftdata-and-query
Thank you so much for your help and these videos!! Love your stuff!@@tundsdev
We’re going places alright thanks to you 🙏 😂 just another great video ❤
Suggestion: vid no.4 Sync the app with iCloud 😬 no pressure. I don’t need it but it’s just a suggestion. 👋
Thanks 🫂
good video! many thinks!
Glad you liked it!
Thanks so much for this series! It's really helpful!
Just one thing, between video parts, I'm noticing some continuity issues. For example, at 1:12 I see there's code for .sheet, but I don't have that at all. I double-checked the Github repo and that also has what I have. Where did this new code come from? I've been following each video part very closely and did not see any modification to this part of the code in a prior part. Can you please explain or perhaps point to an updated Github repo? Thanks!
Hi thanks, this is part 3 as the title states if you watched the whole series from part 1. You’d see this sheet code for editing a todo 👌🏾
@@tundsdev Yes, I started the whole series from part 1 and have the sheet code. However, it's very different from what I have, and I didn't see any changes made to the code in the video.
best
Thanks for the vids man! How would we be able to fetch only items that match today's date?
Thanks, I cover this in the first vid of this course (link below) that shows you how to filter completed items but essentially you’d use a predicate on filter on the date that is in today
Build A To Do List App using SwiftData (Swift Data Tutorials)
ruclips.net/p/PLvUWi5tdh92wZ5_iDMcBpenwTgFNan9T7
@@tundsdev I followed that but got stuck at the last hurdle 😅 couldn't figure out what to put after '=='
I had set a constant called 'today' to Date() and insert this but I kept getting 'Cannot use instance member 'today' within property initializer; property initializers run before 'self' is available'
I'm still super noob so not sure what I'm doing wrong
Hey no worries, so the equal wont work cos that is comparing the actual date to now instead you want to check if a todo item is in today.
Here’s a link with examples hopefully this helps 👌🏾
stackoverflow.com/questions/39345101/swift-check-if-a-timestamp-is-yesterday-today-tomorrow-or-x-days-ago
Could you do a tutorial of download data from a REST API and saving that data into SwiftData?
It’s coming up very soon 🫡
Just noticed that my filteredItems is returning ONLY Items and not Categories as well. Could it be the definition? Too Quick on the comment didn't watch long enough...sorry.
This works for one query on the dataset creating the List but how would filteredItems work when you section the list for Active and Completed items? I ended up in a continuous loop. I'm thinking a List to replace the the display of the two sections when searchquery is not empty and a list with the two sections showing when searchQuery is empty.
I would just have two ForEach’s & have two query macros that use the filter predicate to show completed & uncompleted. Then you can just have two sections 👌🏾
@@tundsdev Already have that so I don't use allItems Query, but filteredItems refers ONLY to AllItems(my name) hence my thinking to show a list of the filtered items (1 section) when searchQuery has content and two sections when searchQuery is empty.
//MARK: - QUERIES
@Query(sort:\ToDoItem.timestamp, order:.reverse) private var allItemsza: [ToDoItem]
@Query(filter: #Predicate
{!$0.isCompleted},
sort: [SortDescriptor(\ToDoItem.timestamp, order: .reverse)]) var activeToDo: [ToDoItem]
@Query(filter: #Predicate
{$0.isCompleted},
sort: [SortDescriptor(\ToDoItem.timestamp, order: .reverse)]) var completedToDo: [ToDoItem]
var filteredItems: [ToDoItem] {
if searchString.isEmpty {
return allItemsza
}
let filteredItems = allItemsza.compactMap { item in
let titleContainsQuery = item.title.range(
of: searchString,
options: .caseInsensitive) != nil
return titleContainsQuery ? item : nil
}
return filteredItems
}
I was wondering why the list was getting redrawn each time a simple computed property was changing, but it is because searchQuery is declared with @State
Firstly, thank for this!
Secondly, are you sure this is the right way we should be filtering?
As far as I can see -- and feel free to correct -- we are still fetching 100% of the database.
And then, we're filtering those (possibly thousands) of entries.
If you have, say a diary app, that's going to be a big DB hit after years of use.
It seems to me that we need to be filtering at the query level, with a predicate.
Regards.
Hey for a big dataset, i would actually tweak this approach. But for something simple like this it should be fine. I also have an upcoming paid course that will explore efficient queries but this is just something quick and easy.
For bigger datasets i.e over 50k records it would be nice in the upcoming betas if Apple released a way to trigger/update the query & sorting kinda like how you can update the sort order with FetchRequest👌🏾
Value of type '[IngredientItem]' has no member 'Name'
why am i getting this error?
Really good videos buddy! How much do you make on this channel if you don't mind me asking? Is it upwards of $50,000 per year?
Thanks glad you enjoy it 👌🏾