Add, edit, move, and delete items in a List in SwiftUI | Bootcamp #31

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

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

  • @shost666
    @shost666 2 года назад +36

    And for the NavigationBarItems that are now deprecated, we should be using toolbar:
    .toolbar {
    ToolbarItem(placement: .navigationBarLeading) {
    EditButton()
    }
    ToolbarItem(placement: .navigationBarTrailing) {
    addButton
    }
    }

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

      Thank you, Thank you so much :):)

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

      tks @shost666! it was very helpful

    • @GeiaHc
      @GeiaHc 6 месяцев назад +1

      This entire course needs to be redone. It doesn't work anymore.

    • @ConfidentlyRong-jo5yt
      @ConfidentlyRong-jo5yt 4 месяца назад

      Thanks! I initially thought that dealing with deprecated code would be annoying but I'm finding it to be quite nice. Cool seeing how thing were and how they've been "updated" sense.

  • @Jimmy-jt8ip
    @Jimmy-jt8ip 3 года назад +17

    As I want to mention, on the latest version of Xcode. We should add a () after the style, for example : .listStyle(GroupedListStyle) should be change to .listStyle(GroupedListStyle()) . Others listStyle as well.

  • @KimbrellBrad
    @KimbrellBrad 3 года назад +4

    Never knew about eliminating those variables in the move and delete calls. Very clean! Many new things here and I have used lists (and fought formatting them) in so many projects! Thanks Nick!

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

    Nick thanks for this fantastic video, your knowledge is pretty valuable for me, keep it for me.

  • @pazuzutru-truluv7094
    @pazuzutru-truluv7094 2 года назад +1

    Thank you - just brilliant and has helped me even more than CodingWithChris, which is a little disloyal, but he didn't get me where I needed to be for my current project challenge

  • @Baxishoff
    @Baxishoff 3 месяца назад

    Thanks for the great content, Nick. Learning a lot from your vids. I have the below questions:
    1. swiftUI is not giving the collapsable list by default anymore. Looks like there is an extra step I have to take but not sure what it is.
    2. Most important one. I have the code correct. I am able to add, edit and stuff. The only thing, when I move/reorder items in the list, they resist and get back to their own place. Any thoughts on that one?
    Thanks a lot in advance.

  • @tariqAlmazyad
    @tariqAlmazyad 3 года назад +3

    I suggest to show at the beginning what you will demonstrate in video demo , it would be amazing .

    • @SwiftfulThinking
      @SwiftfulThinking  3 года назад +2

      Thanks for the suggestion Tariq! That's a great idea haha

    • @tariqAlmazyad
      @tariqAlmazyad 3 года назад +1

      @@SwiftfulThinking your content is super amazing. Sometimes I come to your videos to see if you have better implementations in some stuff .

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

      As always, another great tutorial! I love how you put a prototype together while showing the modifiers.

  • @FernandoSemprun2709
    @FernandoSemprun2709 8 дней назад

    It was fantastic. Hopefully my list items can be buttons… what I missed is customization of delete function to work for all sections, I guess that was a tad too involved…

  • @mattrutkowski5305
    @mattrutkowski5305 3 месяца назад +4

    iOS 17.5
    To get the sections to collapse you have declare a Boolean variable (e.g.
    @State var isExpanded:Bool=true
    )
    , and then add an initializer of isExpanded to the Section(e.g.
    Section(isExpanded: $isExpanded) then all the other stuff
    ). Bind the initializer to your Boolean and add the .listStyle(.sidebar) modifier to your List. Chevron is back!

    • @KatieZhou-w8s
      @KatieZhou-w8s 3 месяца назад

      I wrote this and it worked, but I still don't know how to use listStyle to make this happen. Could you please clarify further?
      List {
      Section(
      header:
      HStack {
      Text("Fruits")
      Spacer()
      Button(action: {
      withAnimation {
      isExpanded.toggle()
      }
      }, label: {
      Image(systemName: isExpanded ? "chevron.down" : "chevron.right")
      .foregroundColor(.red)
      })
      }
      ) {
      if isExpanded {
      ForEach(fruits, id: \.self) { fruit in
      Text(fruit.capitalized)
      }

    • @shreyapallan5704
      @shreyapallan5704 Месяц назад

      Thannnkkkk YOUUUUUUUU!!! You're the absolute best !!

    • @shreyapallan5704
      @shreyapallan5704 Месяц назад

      @@KatieZhou-w8s
      1) adding @State var isExpanded:Bool=true
      and then

    • @shreyapallan5704
      @shreyapallan5704 Месяц назад +1

      Declaring : @State var isExpanded: Bool = true
      and then
      List {
      Section(isExpanded: $isExpanded) {
      ForEach(fruits, id: \.self) { fruit in
      Text(fruit.uppercased())
      }
      .onDelete(perform: delete)
      } header: {
      Text("Fruits")
      }
      }
      .listStyle(.sidebar)
      is what worked for me for the collapsible section

  • @RoshniParekh-h6x
    @RoshniParekh-h6x Год назад

    A very very helpful tutorial, I am getting trough all tutorial videos, your SwiftUI Bootcamp is totally helpful!! Thank you for posting.

  • @marshallross
    @marshallross 2 года назад +1

    So fresh and so clean!

  • @stelluspereira
    @stelluspereira 6 месяцев назад +1

    Nick,
    THANKYOU ,Another very nice lesson , very very useful,
    #1 Section header does not show the Shevron icon , or even the color is not blue , may be new iOS the attributes are different?
    (I tried iPhone, iPad etc, no luck), may be something I am doing wrong !
    >>
    Section(
    header: Text("Fruits")) {
    ForEach(fruits, id: \.self) {fruit in
    Text(fruit.capitalized)
    }
    #2 also the styles does not change ... for example
    >>
    .listStyle(SidebarListStyle())

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

    Hi, Nick this video is great, I just wanted to thank you, you're the best!!

  • @andrejkling3886
    @andrejkling3886 3 года назад +2

    Excellent lesson Nick... thank you

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

    You content is very good; if not excellent. Keep up the good work; looking forward to seeing more. However a small point...indices, plural of index, are not pronounced "in dices". They are pronounced(phonetically).... "in dih seas". Many words that end in "x" are similar...such as matrix.

  • @airinfinite9067
    @airinfinite9067 2 года назад

    Thank you for delivering so nice tutorials!

  • @magedmohmed4403
    @magedmohmed4403 2 года назад

    Thank you nick , your explanation is very useful for me

  • @beemercycle
    @beemercycle 2 года назад

    Nice Tutorial! Very helpful. Gave me lots of new things to try out.

  • @111AlexF
    @111AlexF 2 года назад

    Thank you! It was very helpful for me!!

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

    Thank you, very helpful greetings from Austria

  • @vladimirmoor
    @vladimirmoor 3 года назад +1

    Big thanks for your work!

  • @coffeeCatPeanutDust
    @coffeeCatPeanutDust 3 года назад +1

    Thank you so much for this great content

  • @sergiuprodan360
    @sergiuprodan360 3 года назад +4

    tip regarding embedding in a view which is not in the suggestion list: choose the "Embed..." option which will automatically allow you to type the view in which you want to embed something.

  • @felipemarques7531
    @felipemarques7531 2 года назад

    That's more like it! Sick!

  • @БорисЗиновьев-с3х
    @БорисЗиновьев-с3х 2 года назад

    Best tutorial! Thank you a lot!

  • @liliaruiz2485
    @liliaruiz2485 2 года назад

    Thanks. Great tutorial!!!

  • @foreverme599
    @foreverme599 3 года назад +1

    Hey Nick nice videos they help a lot. My question is how do you make two different text field add into each other and show on a label but within a list? Like a little calculator.

  • @dugrut1325
    @dugrut1325 2 года назад

    I learnt so much my ears are dripping... It just wont stay in!

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

    Awesome tutorial

  • @randlyce
    @randlyce 3 года назад

    This is really helpful i've been trying to color my list

  • @andrejkling3886
    @andrejkling3886 3 года назад +1

    Good lesson... thank you

  • @navsings5059
    @navsings5059 2 года назад

    Great video! Thanks!

  • @eliasmehssatou5141
    @eliasmehssatou5141 3 года назад

    Great vid! Do you think it would be feasible to make one or multiple Sections collapsed at the start?

  • @jonas14812
    @jonas14812 3 года назад +2

    Amazing video, just what the doctor ordered

  • @amatijaca
    @amatijaca 2 года назад

    Thank you for a terrific tutorijal ! I noticed that as soon as you added the list, the background around the list turned grey. Is there a way to change that background grey colour to something else?

  • @punkysuen
    @punkysuen 2 года назад

    Great video! If I want to use TextField for user to edit the string of names of fruits, which tutorial should I watch? I tried to use TextField with NavigationLink, but failed to equal the new string to finish the change. Thank you.

  • @恒张-i5p
    @恒张-i5p 2 года назад +1

    Hey Nick, if I use the section dynamic from data, with delete action, where can I get the section index, the video just show how to get the row index

  • @Nunny25
    @Nunny25 3 года назад

    Great tutorial, thanks

  • @dadrewco100
    @dadrewco100 3 года назад

    I am learning this thanks .

  • @JeckyKA
    @JeckyKA 3 года назад

    awesome! thank you so much!

  • @scottalucas
    @scottalucas 3 года назад +2

    Thanks, great video! I'm wondering if it's possible to move list items between sections. Say, for example, you lose and argument with you wife after she insists tomatoes are fruits. What then? Is is possible to move between sections? I'm trying to do this with a hierarchical list because, at least with that type of list, the data elements are all from the same data source (and not split into pre-defined "fruits" and "veggies" arrays).
    Thanks again.

    • @SwiftfulThinking
      @SwiftfulThinking  3 года назад +4

      Well whether or not they are fruits, we should probably assume your wife will win the argument anyway. Haha. This is very possible, but it's a little tricky. You would first need to add sections to the list and then have logic for when you move an item, which section is it ending in. Unfortunately this is a little hard for me to explain in a comment without doing a video on it lol

    • @manwithllama
      @manwithllama 2 года назад +1

      @@SwiftfulThinking I would LOVE a video on this! Love your teaching style. :)

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

    Why did the section-fold/unfold-option appear, when you added the Editbutton?

  • @Pedro76mchlkg
    @Pedro76mchlkg 3 года назад +1

    Thank you. Do you know if it's possible to make the list editable directly on the row? Like remainders app?

    • @SwiftfulThinking
      @SwiftfulThinking  3 года назад +1

      Hello! Yes, it is possible but it is harder than this video 😂

    • @Pedro76mchlkg
      @Pedro76mchlkg 3 года назад

      ​@@SwiftfulThinking, that's what I thought, I am trying to do this for days. But at least I am starting to understand better the SwiftUI concept. I am watching all your tutorials, your explanations are very good. Thank you again!

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

    Very useful!

  • @andresraigoza2082
    @andresraigoza2082 2 года назад

    Great tutorial!!! Thanks again. But I ran into an issue. accentColor will be deprecated, so I used tint, but now the arrow that perform the collapsible function does not change color. What should I do to change the color of this arrow?

    • @SwiftfulThinking
      @SwiftfulThinking  2 года назад +1

      I think .tint is the replacement for .accentColor

  • @suryaKoneru-rz9or
    @suryaKoneru-rz9or 5 месяцев назад

    Hi there surya pavan koneru here, hope you are doing good. here adding edit done edit came for first most section only what to do to come for second section ??

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

    Great video, but does someone know how to take off the gray line under the text in each row

  • @kath89-89
    @kath89-89 2 месяца назад +1

    Does anyone know how to get the move function to save to newOffset? ✨ Thank you.

    • @mykosen5679
      @mykosen5679 Месяц назад

      If you have copied the code as in the video it should be working. Try running it in the simulator - I had issues with it in the preview where the rows were disappearing and reappearing when I moved them around.

  • @pfarinav
    @pfarinav 2 года назад

    14:13
    Can we just call the method on the array? Same for delete?
    Something like:
    .onDelete(perform: fruits.remove) ?
    (I have not finished the video, so maybe we can and its mentioned after that :D )

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

    Thank lot Bro...🥰

  • @emdutt4012
    @emdutt4012 2 года назад

    hey, nick, there is already a built-in editbutton() by SwiftUI, but we need to create a button by oueselves for adding to the list. why it is?

  • @offthedeepend762
    @offthedeepend762 4 месяца назад +3

    So good until "tomato" was put in the veggies array.

  • @raimitis
    @raimitis 2 года назад

    Hi, accentColor will be depricated and suggestion is to use "tint(Color.red)". Only issue with that is collaps arrows standard blue color does not changes. Any thoughts?

  • @DavidNitzscheBell
    @DavidNitzscheBell 2 года назад +1

    when you say "edit" I thought it meant edit the items in the list, not the order of the list.

  • @edutyl9372
    @edutyl9372 2 года назад

    Thanks

  • @Jump_Jay
    @Jump_Jay 2 года назад

    Question, can you put a button inside a list?

  • @dugrut1325
    @dugrut1325 2 года назад +1

    OH MY... my brain hurts!

  • @danielwatson6529
    @danielwatson6529 2 года назад

    ah thing problem with this awesome delete func, is I don't know how to pass in another parameter, so like it would be awesome if I can have it take a managed object context so that I can swipe to delete directly from the moc. I will find a way!

    • @danielwatson6529
      @danielwatson6529 2 года назад

      although, im happy with this:
      .onDelete(perform: { indexSet in
      restaurant.delete(at: indexSet, container: container)
      })
      I think in the future if I wanted to make it as flush as the inbuilt one I would have to make an extension on ForEach and change this: 'Optional Void>' to accept my parameter. But for now, I am super happy that I could follow along and get this far! thanks for all your help buddy!!

    • @danielwatson6529
      @danielwatson6529 2 года назад

      HA you beautiful man! bootcamp #58 helps and even more so; here's a couple I made, strangely I dont need my fetchAll() after; .removeFromMenus_ but I do when doing the in build delete function
      .swipeActions(edge: .trailing) {
      Button("Delete") {
      self.context.delete(restaurant)
      try? self.context.save()
      self.fetchAll()
      }
      .tint(.red)
      }
      .swipeActions(edge: .trailing) {
      Button("Remove") {
      restaurant.removeFromMenus_(menu)
      try? self.context.save()
      }
      .tint(.yellow)

  • @DavidNitzscheBell
    @DavidNitzscheBell 3 года назад +1

    How about a way to do all this with a list of complex objects, not just strings?

    • @SwiftfulThinking
      @SwiftfulThinking  3 года назад

      I do this in the SwiftUI Todo List playlist on my channel

    • @DavidNitzscheBell
      @DavidNitzscheBell 2 года назад

      @@SwiftfulThinking No, that's not really a complex object. I meant a struct that has multiple strings, for instance. Maybe a date value. Maybe an integer. For this, you need a screen to input the new record. and then, you need a way to edit an existing record. Your playlist is basically just adding Strings, wrapped in a struct with an id and a bool. There is no data entry or data modification screen. I'll keep looking. It seems no one has done this. At least, not that I can find.

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

    Why is the "header" of the section not colored on mine? Like FRUITS and VEGGIE

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

      Same thing, first of all accent color is deprecated, secondly the old header completion is also deprecated, now you should provide content first then header, in a section.
      Anyways back to the question, I don't think it matters we can always change the foreground colour of the header text.

  • @최승기-g8f
    @최승기-g8f 3 года назад

    Great!!!

  • @REDCoder-xs6pw
    @REDCoder-xs6pw 11 месяцев назад

    Neat !!!

  • @doctorstrangelove798
    @doctorstrangelove798 2 года назад

    i downloaded the recent version (13.1) of xcode and all i get are odd errors that do not show up in the videos - is the recent version of xcode stable?

    • @SwiftfulThinking
      @SwiftfulThinking  2 года назад

      I'm still on 13.0 but I don't think Apple would release a version that isn't stable haha. They would keep it in beta if there were big issues. Maybe you have a typo somewhere that's cascading across the project?

    • @doctorstrangelove798
      @doctorstrangelove798 2 года назад

      Love your tutorials - looks like you use 12.3 for most of the tutorials. I am going to step back to version 12.3. PS they just released version 13.2.

    • @doctorstrangelove798
      @doctorstrangelove798 2 года назад

      @@SwiftfulThinking Ok, its the same bug i found with not recognizing variables is scope - i changed the name of the function, hit resume, everything works, changed back to the original func name and everything works. There is a problem with the interpreter getting lost if the closure sequence gets interrupted or complicated (missing brackets while typing)

  • @nijatnamazzade7413
    @nijatnamazzade7413 2 года назад

    Hi, in the latest version of xcode the edit button doesn't appear

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

      You might have forgotten to add NavigationView. It works as shown.

  • @williamwildsmith5162
    @williamwildsmith5162 2 года назад

    Hi Nick.
    .navigationBarItem is deprecated.
    So I'm trying .toolbar instead. . .
    .toolbar {
    ToolbarItem(placement: .navigationBarLeading) {
    EditButton()
    }
    ToolbarItem(placement: .navigationBarTrailing) {
    addButton
    }
    }
    However, when I use .toolbar, with EditButton(), the Section collapsibility disappears.
    Any thoughts?
    Thank you
    😀

    • @raimitis
      @raimitis 2 года назад

      use .listStyle(SidebarListStyle())

    • @irvingkyrie2823
      @irvingkyrie2823 4 месяца назад

      ​@@raimitisDid it work when you added it?

    • @raimitis
      @raimitis 4 месяца назад

      @@irvingkyrie2823 then it worked, not sute if it does now

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

    how to listen edit button and done button clicked

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

    'Indices' is 'in-dih-cees'

  • @anrg
    @anrg 2 года назад +1

    . navigationBarItems gonna deprecated in near future

    • @SwiftfulThinking
      @SwiftfulThinking  2 года назад

      Use .toolbar with ToolbarItems that have Placement of .navigationBarLeading and .navigationBarTrailing

  • @KingTode
    @KingTode 2 года назад +1

    just fyi, indices is pronounced in-duh-seez, not in-dice-is

  • @Horizon-tr6iy
    @Horizon-tr6iy Год назад

    10:48