SwiftUI - Reorder a List (2 Ways)

Поділитися
Вставка
  • Опубліковано 25 лис 2024

КОМЕНТАРІ • 27

  • @seanallen
    @seanallen  2 місяці тому

    Learn more Swift & SwiftUI with my iOS Dev courses at seanallen.teachable.com

  • @AndreiChenchik
    @AndreiChenchik 2 місяці тому +5

    I’m wondering, since array have ordering built in already, why adding ordering property in the first place? Not just persisting the whole array. Is there any cons on default solution? Thanks!

    • @EvgeniiBondarev
      @EvgeniiBondarev 2 місяці тому +1

      I guess the key thing we have to keep in mind is that all the code here is just a sample created to show some SwiftUI feature and its capabilities. In reality we always have much more complicated stuff and need to handle it in a different way, so here indices is just a simplest value of each element that is easy to understand and track. Keeping indices in objects makes no sense in a real code, I guess.

    • @didgeoridoo
      @didgeoridoo 2 місяці тому

      SwiftData seems to not really care about the ordering of one-to-many relationships, and will happily and unpredictably scramble an array of [SubTasks] that live in Task.subTasks. This seems to especially occur when using CloudKit syncing. I’ve taken to explicitly capturing display order for these related objects, just as Sean does here.

    • @jj_man123
      @jj_man123 Місяць тому

      Imagine if you wanted to persist the order in an external data source, so that when the user returns to the app the order remains the same. You would need some property to track the order so you can sort the list by that value on load. I hope I understood what you meant and helped a little with why you would use a property to track the list order number

  • @Zod_JB
    @Zod_JB 2 місяці тому +1

    Great video Sean. Glad I found your content. The other guy who’s content I was learning from is very soft spoken and puts me to sleep.
    Thanks for not putting me to sleep 😂

    • @seanallen
      @seanallen  2 місяці тому +1

      Happy to hear it :)

  • @shocktheworld8654
    @shocktheworld8654 2 місяці тому +1

    I’m currently getting my iOS development certification through my local college. Our instructor wants us to learn storyboards before SwiftUI because he says it’s still commonly used and a bit easier because it’s visual. With that being said can you make some storyboard tutorials as well as describe the logic? Do you already have some storyboard videos on your channel? If so can you link them to me. I love your videos and I’m going to have you to thank when my dreams of becoming an iOS developer come true.

  • @nym49
    @nym49 2 місяці тому +1

    How can we reorder multiple list items by picking them up with the multi-touch gesture using Swift UI? Like in the Photos or Files app or with app icons on the Home Screen?

  • @bryceellis112
    @bryceellis112 2 місяці тому +1

    Curious to test if this works on watchOS!

  • @bobdabuilder9447
    @bobdabuilder9447 2 місяці тому

    I really like this concept has anyone display it over a day schedule to then use the on move to to change the time a to do list item is scheduled also how can you allow the user to overlap the items

  • @nileshjdarji
    @nileshjdarji 2 місяці тому +1

    This is awesome. Thank you.

    • @seanallen
      @seanallen  2 місяці тому

      Glad you liked it!

  • @brunofay1
    @brunofay1 2 місяці тому

    hey sean.
    Could you tell me how to change to the trailing closure syntax using only keyboard keys?
    I'm starting out in Swift and I can't find how to do this.
    Thanks!

  • @christianburrus
    @christianburrus 2 місяці тому

    I was able to recreate option 1 but it doesn't seem to be working when it's in a scrollview. Is there a way to address this issue?

  • @alibatkanocal1620
    @alibatkanocal1620 2 місяці тому

    hi I know this is not about video but I can not find a solution how can I use viewDidLoad in swift

  • @TheGustavo888
    @TheGustavo888 Місяць тому

    How can I reorder sections of items and items inside a section?

  • @ZeroTorySeats
    @ZeroTorySeats 2 місяці тому +1

    This is the first video I've watched by you that I didn't understand. I feel like you could have explained the counter code a bit better.

    • @EvgeniiBondarev
      @EvgeniiBondarev 2 місяці тому +1

      Author is just rewriting the indices saved in the array elements to 0, 1, 2... according to their order in a new array after movements. Another question is why having indices in array elements if array has indices so we need to keep them in sync manually.

  • @hackwithrama
    @hackwithrama 2 місяці тому

    How to update the Swift Data Query after moving the item, with no position property in model

  • @Anu_was_here
    @Anu_was_here 2 місяці тому

    But isn’t Lists ordered already? Why not presist the list it self? 😢

    • @seanallen
      @seanallen  2 місяці тому +1

      Depends on how you are persisting. Core Data / Swift Data doesn't work like that.

  • @ZeroTorySeats
    @ZeroTorySeats 2 місяці тому

    If you want to use onMove but also want to have editActions like delete, is that possible? How would you do that?

    • @luisroberto3072
      @luisroberto3072 2 місяці тому

      you can use the .onDelete(perform: ) modifier

  • @umarparacha653
    @umarparacha653 2 місяці тому

    Good to see Allen
    Now new apps build with swiftui instead of uikit
    New developer focus on swiftui or uikit
    What yu thought ?