It was an easy Question, but want to ask, how we can change the text element area and How we can declare a list first and then , add all other elements, May You please HELP
The Solution of the code:
//
// ContentView.swift
// Practice-6
//
// Created by Sam Grover on 23/05/22.
//
import SwiftUI
struct ContentView: View {
@State var array: Array? = [String]()
var body: some View {
HStack{
VStack{
Button("Nill") {
array = nil
}
Button("Add") {
array?.append("Sam")
array?.append("Tam")
array?.append("Fam")
}
if array == nil{
Text("Please Tap on Second Button to add elements")
}else{
NavigationView{
List((array)!, id: \.self){ r in
Text(r)
}
}
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}