I am trying to pass static array data from my preview provider to main class file but its not being called and I get empty data every time. How to resolve this. Any help would be appreciated. Here is my below code that I have tried till far
struct CountryDetails: Identifiable{
internal init(id: Int, City: String, State: String, Country: String) {
self.id = id
self.City = City
self.State = State
self.Country = Country
}
let id: Int
let City: String
let State: String
let Country: String
}
struct ContentView: View {
@Binding var country: [CountryDetails]
var body: some View {
NavigationView{
List{
ForEach(country) { country in
Text(country.City)
}
}
.navigationTitle("Country's Details")
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
OtherView()
}
struct OtherView : View {
@State var arr:[CountryDetails] = [
.init(id: 1, City: "Mumbai", State: "Maharashtra", Country: "India" ),
.init(id: 2, City: "Chennai", State: "Tamil Nadu", Country: "India" ),
.init(id: 3, City: "Bengaluru", State: "Karnataka", Country: "India" )
]
var body: some View {
NavigationView {
ContentView(country: $arr)
}
}
}
}