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

Поділитися
Вставка
  • Опубліковано 4 лип 2024
  • ⏭️ Next Video: Sorting In SwiftData - • How To Sort Data In Sw...
    ⏮️ Previous Video: SwiftData Relationships - • Swift Data Relationshi...
    Easily Add Filtering In SwiftData Using Searchable 🕵🏾‍♂️ | Filter in SwiftData
    Build A To-Do List App using SwiftData (Swift Data Tutorials)
    • SwiftData Todo List Ap...
    **********************************
    Timestamps:
    00:00 - Intro
    00:17 - How To Add A Searchbar In SwiftUI
    01:18 - How To Filter Data In SwiftData
    06:53 - How To Filter On Multiple Properties In SwiftData
    09:44 - Handling empty states in SwiftData
    **********************************
    So, how do you filter data in SwiftData using SwiftUI? Well, it's actually quite simple. In this SwiftData Tutorial. We'll be taking a look at how to filter data in SwiftData using the searchable modifier in SwiftUI.
    We'll be filtering out our to-do items' title and category names to display the relevant to-do items to the user.
    **********************************
    Check Out My Courses 👨🏽‍🏫
    Enjoy my teaching style? Check out my other courses on my website that may interest you, they range from beginner to advanced topics within iOS development.
    Link to Website
    tunds.dev/#courses
    **********************************
    Join the crew 🤝
    Want to help support the channel? Become a member with the join link below and get access to exclusive badges and stickers, as well as other perks that are coming soon.
    Become a channel member
    www.youtube.com/@tundsdev/join
    Support in other ways 💕
    You can support me for free and help the channel grow so that I can continue to make the best iOS development content for you by liking, commenting, subscribing, and hitting the notification bell.
    All of this really helps my channel grow and allows me to keep on making content for you. If you’re interested in subscribing to the channel then you can do so with the link below.
    Subscribe to the tundsdev UA-cam channel
    ua-cam.com/users/tundsdev?su...
    **********************************
    Download Source Code
    Interested in looking at the source code? Then check out the GitHub Repo below
    github.com/tunds/youtube-cont...
    **********************************
    EditorKeys
    View Editor Keys Amazing Products with the link below and use the discount code for 10% off any product
    www.editorskeys.com/tundsdev
    Get a 10% Discount Code on any product with the code below
    TUNDSDEV
    See my keyboard cover in action with my review below 👇🏾
    • Increase Your Xcode Pr...
    **********************************
    RØDE Wireless Mic
    amzn.to/3D5qo3V
    RØDE SmartLavPlus Microphone
    amzn.to/3DtVUdG
    2021 Apple MacBook Pro (16-inch, Apple M1 Pro chip with 10‑core CPU and 16‑core GPU, 16GB RAM, 1TB SSD) - Space Grey
    amzn.to/3Drc2fH
    Apple Magic Keyboard with Numeric Keypad (Wireless, Rechargeable)
    amzn.to/3VUctXh
    Apple Magic Mouse
    amzn.to/3sqXSoM
    Secretlab TITAN 2020 Charcoal Blue Gaming Chair
    amzn.to/3D2jVXI
    ErgoFoam Ergonomic Foot Rest for Under Desk
    amzn.to/3srJOLM
    Lumbar Support Pillow
    amzn.to/3eXVfrg
    Macbook Stand for Apple Macbook and All Notebooks
    amzn.to/3DqG7vR
    Portable Chair Green Screen Background
    amzn.to/3gG62GU
    **********************************
    #iosdev #iosdevelopment #swift #swiftlanguage #xcode #appdevelopment #mobileappdevelopment #iosappdevelopment #appdeveloper #iosprogramming #iosengineer #appdevelopmenttips #iosdevelopmenttips #swiftui

КОМЕНТАРІ • 45

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

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

  • @LG-ve9us
    @LG-ve9us 4 місяці тому +1

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

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

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

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

    Looking forward to this!

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

      Great to hear 👌🏾

  • @andres121231
    @andres121231 3 місяці тому +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  3 місяці тому

      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
      ua-cam.com/video/V4kHAKmC53Y/v-deo.html

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

    Best SwiftData tutorial on UTube

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

      Thanks 🤝

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

    good video! many thinks!

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

    You are the best man, really !

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

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

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

      @@tundsdev keep up the good work 👍

  • @user-tr4vc9zj7i
    @user-tr4vc9zj7i 3 місяці тому

    best

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

  • @pgong415
    @pgong415 11 місяців тому +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  11 місяців тому

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

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

    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  4 місяці тому +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

  • @user-ju4dz7pu3q
    @user-ju4dz7pu3q 8 місяців тому

    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  8 місяців тому

      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

    • @user-ju4dz7pu3q
      @user-ju4dz7pu3q 8 місяців тому +1

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

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

    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.

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

    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

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

    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  8 місяців тому

      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 8 місяців тому

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

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

    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  10 місяців тому

      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 10 місяців тому

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

  • @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)
      ua-cam.com/play/PLvUWi5tdh92wZ5_iDMcBpenwTgFNan9T7.html

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

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

  • @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 7 місяців тому

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