And for the NavigationBarItems that are now deprecated, we should be using toolbar: .toolbar { ToolbarItem(placement: .navigationBarLeading) { EditButton() } ToolbarItem(placement: .navigationBarTrailing) { addButton } }
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.
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.
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!
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
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.
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…
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!
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) }
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
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())
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.
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.
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.
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?
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.
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.
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
@@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!
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?
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 ??
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.
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 )
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?
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!
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!!
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)
@@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.
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.
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?
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?
@@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)
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 😀
And for the NavigationBarItems that are now deprecated, we should be using toolbar:
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
EditButton()
}
ToolbarItem(placement: .navigationBarTrailing) {
addButton
}
}
Thank you, Thank you so much :):)
tks @shost666! it was very helpful
This entire course needs to be redone. It doesn't work anymore.
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.
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.
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!
Thanks for watching Brad!!
Nick thanks for this fantastic video, your knowledge is pretty valuable for me, keep it for me.
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
Well I’m glad this video helped 👍
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.
I suggest to show at the beginning what you will demonstrate in video demo , it would be amazing .
Thanks for the suggestion Tariq! That's a great idea haha
@@SwiftfulThinking your content is super amazing. Sometimes I come to your videos to see if you have better implementations in some stuff .
As always, another great tutorial! I love how you put a prototype together while showing the modifiers.
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…
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!
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)
}
Thannnkkkk YOUUUUUUUU!!! You're the absolute best !!
@@KatieZhou-w8s
1) adding @State var isExpanded:Bool=true
and then
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
A very very helpful tutorial, I am getting trough all tutorial videos, your SwiftUI Bootcamp is totally helpful!! Thank you for posting.
So fresh and so clean!
Thanks Marshall
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())
Hi, Nick this video is great, I just wanted to thank you, you're the best!!
Excellent lesson Nick... thank you
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.
Thank you for delivering so nice tutorials!
Thank you nick , your explanation is very useful for me
Nice Tutorial! Very helpful. Gave me lots of new things to try out.
Thank you! It was very helpful for me!!
Thank you, very helpful greetings from Austria
Big thanks for your work!
Thanks for watching Владимир!
Thank you so much for this great content
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.
Oh yea... great advice Sergiu!
That's more like it! Sick!
Best tutorial! Thank you a lot!
Thanks. Great tutorial!!!
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.
I learnt so much my ears are dripping... It just wont stay in!
Awesome tutorial
This is really helpful i've been trying to color my list
Hey Arman! What colors are you using? haha
Good lesson... thank you
Great video! Thanks!
Great vid! Do you think it would be feasible to make one or multiple Sections collapsed at the start?
I think anything is feasible 🧐🤓
Amazing video, just what the doctor ordered
Hahaha thanks for watching Jonas!
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?
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.
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
Great tutorial, thanks
Thanks Charlie!
I am learning this thanks .
awesome! thank you so much!
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.
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
@@SwiftfulThinking I would LOVE a video on this! Love your teaching style. :)
Why did the section-fold/unfold-option appear, when you added the Editbutton?
Thank you. Do you know if it's possible to make the list editable directly on the row? Like remainders app?
Hello! Yes, it is possible but it is harder than this video 😂
@@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!
Very useful!
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?
I think .tint is the replacement for .accentColor
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 ??
Great video, but does someone know how to take off the gray line under the text in each row
Does anyone know how to get the move function to save to newOffset? ✨ Thank you.
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.
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 )
Thank lot Bro...🥰
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?
So good until "tomato" was put in the veggies array.
It is a fruit !!!!
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?
when you say "edit" I thought it meant edit the items in the list, not the order of the list.
Thanks
Question, can you put a button inside a list?
OH MY... my brain hurts!
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!
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!!
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)
How about a way to do all this with a list of complex objects, not just strings?
I do this in the SwiftUI Todo List playlist on my channel
@@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.
Why is the "header" of the section not colored on mine? Like FRUITS and VEGGIE
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.
Great!!!
Neat !!!
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?
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?
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.
@@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)
Hi, in the latest version of xcode the edit button doesn't appear
You might have forgotten to add NavigationView. It works as shown.
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
😀
use .listStyle(SidebarListStyle())
@@raimitisDid it work when you added it?
@@irvingkyrie2823 then it worked, not sute if it does now
how to listen edit button and done button clicked
'Indices' is 'in-dih-cees'
. navigationBarItems gonna deprecated in near future
Use .toolbar with ToolbarItems that have Placement of .navigationBarLeading and .navigationBarTrailing
just fyi, indices is pronounced in-duh-seez, not in-dice-is
10:48