SwiftUI Lists & Forms ForEach

ForEach

Iterate over collections to generate views dynamically using ForEach.


ForEach

Render a list of items using ForEach.

Example

Demo.swift

ContentView.swift

App.swift

import SwiftUI

struct ForEachDemo: View {
  let nums = [1,2,3]
  var body: some View {
VStack {
  ForEach(nums, id: \.self) { n in
    Text("Item \(n)")
  }
}
} }

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *