Argument passed to call that takes no arguments SwiftUI for MapView

35 Views Asked by At

I am passing an argument locationPins into MyMapView as a Binding and then again pass locationPins to MapView as another Binding. But when I pass it to MapView as an argument I get error: "Argument passed to call that takes no arguments"

struct MyMapView: View {
@Binding var locationPins: [GpsData.MyEndPt]

var body: some View {
    TabView {
        NavigationView {
            ZStack {
                VStack (alignment: .leading){
                    MapView(locationPins: locationPins) // <<----- ERROR HERE
                        .ignoresSafeArea()
                        
                }
            }
            .safeAreaInset(edge: .bottom) {
              Color.clear
                .frame(height: 0)
                .background(.white)
            }

        }
    }
    
}

struct MapView: UIViewRepresentable {
    @Binding var locationPins: [GpsData.MyEndPt]
    @State var mylocationPins: [GpsData.MyEndPt] = []
    
    init() {
        self.mylocationPins = toPins(locationPins: self.locationPins)
    }

    func toPins(locationPins: [GpsData.MyEndPt]) -> [GpsData.MyEndPt] {
        
        for location in locationPins {
         // use locationPins to populate myLocationPins and return
        }
        return mylocationPins
    }

}

If I remove the Binding definition of locationPins inside MapView, then I cannot pass the value.

How to fix this?

0

There are 0 best solutions below