SwiftData Background Tasks: Massively Improve Your Apps Performance | SwiftData Tutorial | #12

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

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

  • @keegan8176
    @keegan8176 3 дня назад +1

    Thank you 🙌 do you have any videos on how to query it not on the main thread like you mentioned at the end?

  • @rafaelplinio6527
    @rafaelplinio6527 8 месяцев назад +2

    Nice video as always and yes... tutorial about Profile in Instruments!

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

      You got it!

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

    Helpful. Thank you sir !

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

    Awesome video, thanks! YES! I'd really love to see a tutorial about instruments

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

      You got it!

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

    great video, as always. +1 on a video on instruments!! I have a swift data project that is really bogging down when initiating a view that includes a dynamic filter predicate. I have no idea how to troubleshoot. thanks for what you do

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

      Sounds great!

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

    Excellent video on ModelActor macro. It was very helpful.

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

      Glad it was helpful!

  • @chezchezchezchez
    @chezchezchezchez 8 месяцев назад +3

    Can you expand on the "Write a predicate to fetch data" (to avoid the @Query on the main thread)
    My app uses a LOT of @Querys and the main thread is bogged down!
    I need more speed.
    Thanks!

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

      So you can use something like this www.hackingwithswift.com/quick-start/swiftdata/how-to-create-a-custom-fetchdescriptor
      The only downside is that you'd have to manage refreshing the view yourself etc which the query macro does for you automatically.

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

      @@tundsdev so what do you recommend? I’m only a part-time Programmer/hobbyist.
      I would prefer something simplistic.

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

    Yes! A video 2:50 with that tool with be great.

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

      I got you!!!

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

    Yes instruments tutorial!

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

    Thanx for amazing video, but is it working also when i want to update data ?

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

    Why create an actor who you just reap everything into Task{let modelContext = ModelContext(container) ...} ?

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

      You have to use an actor so you can move it off the main thread and isolate it onto it's own thread which is what I explain in the video around 4:20, the ModelActor property wrapper lets you create a context away for the main one

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

      @@tundsdev Hmm. In my test this also does move the operation to a background thread. I haven't done much with actors yet, so maybe actors are the preferred way to do it anyway. Here is the code the way I mean it:
      Task(priority: .background) {
      let newModelContext = ModelContext(TestApp.sharedModelContainer)
      (0...1000).forEach { index in
      let newItem = TestItem(uuid: UUID())
      newModelContext.insert(newItem)
      }
      try? newModelContext.save()
      }

  • @ammarahmad9004
    @ammarahmad9004 5 месяцев назад

    When you set "Strict Concurrency Check" to "Complete", you will get a warning the message "Non-sendable type returned by call to actor-isolated function cannot cross actor boundary", How can void this.

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

      You need to make your model sendable manually by marking it with the @unchecked Sendable pretty good article explaining it here but it's safe to use this since we don't modify the model across different threads.Here's a simple example below.
      @Model
      class MyModel: @unchecked Sendable {
      }

    • @ammarahmad9004
      @ammarahmad9004 5 месяцев назад

      @@tundsdev Thanks for the explanation.

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

      You can fetch using the ModelActor and then stuff a struct with the results and pass that as the struct is Sendable.