From the course: Complete Guide to SwiftUI

Unlock this course with a free trial

Join today to access over 24,600 courses taught by industry experts.

Iteration with ForEach

Iteration with ForEach

- [Instructor] I'm building out my wire frame for my app nicely. However, the order items on top and the menu below have more than one item. You'll need some iteration over a list of these. There's several options in SwiftUI. The simplest is the for each, which works similar to a Swift four loop. So we're going to go to where we have the H stack here. Now this is much easier when you start dealing with H stacks and stuff to actually have a code folding ribbon over here in your code. So I'm going to go over here to X code preferences, and go over here to editing, and turn on the code folding ribbon, which you'll find makes life a lot easier in SwiftUI. And then you can see that we've got the code folding ribbon, which will give us where our stacks are here. And I'm going to go to this H stack for the bottom one here, line 41. And I'm going to code fold it. And the reason I do that is 'cause now I can put code around it real easy, and I can see what I'm doing. So I'm going to put in a…

Contents