Easily Add Filtering In SwiftData Using Searchable 🕵🏾‍♂️ | Filter in SwiftData | #3

Поделиться
HTML-код
  • Опубликовано: 13 окт 2024

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

  • @nileshjdarji
    @nileshjdarji 2 месяца назад

    I am extremely enjoying your this series. Great Job. I learned some cool stuff.

  • @samuelhcohen
    @samuelhcohen Год назад +1

    Watched a few tutorials before I found this one. None of them clicked until this! Thank you, my friend!

  • @andres121231
    @andres121231 7 месяцев назад +1

    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.

    • @tundsdev
      @tundsdev  7 месяцев назад

      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

  • @LG-ve9us
    @LG-ve9us 7 месяцев назад +1

    very good video, well explained and worked perfectly for my application... keep up the great work!

    • @tundsdev
      @tundsdev  7 месяцев назад

      Glad it helped!, be sure to watch the rest of the vids in the playlist!

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

    Best SwiftData tutorial on UTube

  • @dmacharo
    @dmacharo 8 месяцев назад

    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?

    • @tundsdev
      @tundsdev  8 месяцев назад +1

      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

  • @tech_ch1211
    @tech_ch1211 Год назад +1

    You are the best man, really !

    • @tundsdev
      @tundsdev  Год назад +1

      Great to hear, heads up I have an improvement coming soon of this video 👀

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

      @@tundsdev keep up the good work 👍

  • @pgong415
    @pgong415 Год назад +1

    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 ?

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

      Thanks and if you enable the undo manager I think you can undo changes that you’ve made on your persistant store

  • @toastrecon
    @toastrecon Год назад +1

    Looking forward to this!

    • @tundsdev
      @tundsdev  Год назад +1

      Great to hear 👌🏾

  • @JenniferHolub-g2x
    @JenniferHolub-g2x 11 месяцев назад

    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.

    • @tundsdev
      @tundsdev  11 месяцев назад +1

      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

    • @JenniferHolub-g2x
      @JenniferHolub-g2x 11 месяцев назад +1

      Thank you so much for your help and these videos!! Love your stuff!@@tundsdev

  • @sxmiotb2834
    @sxmiotb2834 Год назад +1

    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. 👋

  • @enderslee
    @enderslee Год назад +1

    good video! many thinks!

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

    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
      @tundsdev  Год назад

      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 👌🏾

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

      @@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.

  • @DolHarubang-swift
    @DolHarubang-swift 7 месяцев назад

    best

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

    Thanks for the vids man! How would we be able to fetch only items that match today's date?

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

      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

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

      @@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

    • @tundsdev
      @tundsdev  Год назад +1

      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

  • @vanylaskywalker
    @vanylaskywalker Год назад +1

    Could you do a tutorial of download data from a REST API and saving that data into SwiftData?

    • @tundsdev
      @tundsdev  Год назад +1

      It’s coming up very soon 🫡

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

    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.

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

    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.

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

      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 👌🏾

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

      @@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
      }

  • @markaurelius61
    @markaurelius61 11 месяцев назад

    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

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

    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.

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

      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👌🏾

  • @g3dr0cht
    @g3dr0cht 10 месяцев назад

    Value of type '[IngredientItem]' has no member 'Name'
    why am i getting this error?

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

    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?

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

      Thanks glad you enjoy it 👌🏾