SwiftUI snippet that generates multiple Text() components based on the items in an array.
import SwiftUI struct SomeView: View { @State private var someArray: [String] = ["Igor"] var body: some View { ForEach(someArray, id: \.self) { item in HStack { Text("\(item)") .font(.title3) .fontWeight(.semibold) } } } } #Preview { SomeView() }
import SwiftUI struct SomeView: View { @State private var someArray: [String] = ["Igor"] var body: some View { ForEach(someArray, id: \.self) { item in HStack { Text("\(item)") .font(.title3) .fontWeight(.semibold) .onTapGesture { someArray.remove(at: someArray.firstIndex(of: person ) ?? 0) } } } } } #Preview { SomeView() }