Syntax error please help

Im getting this error at onAppear when I try to get the data from data source and assign it to cities.Please help.Thanks a ton.
Cannot convert value of type ‘()’ to expected argument type ‘(() → Void)?’

this is my code

struct CityView: View {
var body: some View {

    var datasource = DataSource()
    @State var cities:[City] = [City]()
    
    
    VStack{
        
        Text("Hi")
        
    }.onAppear(perform: cities = datasource.getData()). //error on this line
   
    
}

}

Change your .onAppear code to this:

.onAppear {
    cities = datasource.getData()
}

Thank you so much Chris it worked like a charm

1 Like