Mapbox iOS导航SDK不适用于SwiftUI

Mapbox iOS导航SDK不适用于SwiftUI,swiftui,mapbox,mapbox-ios,Swiftui,Mapbox,Mapbox Ios,我得到了一个错误: 类型“NavView”不符合协议“UIViewRepresentable” 这是我的密码。我该怎么办?谢谢使用SwiftUI struct NavView: UIViewRepresentable{ func makeUIView(context: Context) -> NavigationViewController { var viewController: NavigationViewController // Def

我得到了一个错误:

类型“NavView”不符合协议“UIViewRepresentable”

这是我的密码。我该怎么办?谢谢使用SwiftUI

struct NavView: UIViewRepresentable{

    func makeUIView(context: Context) -> NavigationViewController {
        var viewController: NavigationViewController

        // Define two waypoints to travel between
        let origin = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 38.9131752, longitude: -77.0324047), name: "Mapbox")
        let destination = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 38.8977, longitude: -77.0365), name: "White House")

        // Set options
        let options = NavigationRouteOptions(waypoints: [origin, destination])

        // Request a route using MapboxDirections.swift
        Directions.shared.calculate(options) { (waypoints, routes, error) in
            guard let route = routes?.first else { return }
            // Pass the generated route to the the NavigationViewController
            viewController = NavigationViewController(for: route)
            viewController.modalPresentationStyle = .fullScreen

        }
    return viewController
    }

    func updateUIView(_ uiView: NavigationViewController, context: Context) {

    }
}

对于这种情况,应使用
UIViewControllerRepresentable
,如下所示

struct NavView: UIViewControllerRepresentable {

    func makeUIViewController(context: Context) -> NavigationViewController {
        var viewController: NavigationViewController

        // Define two waypoints to travel between
        let origin = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 38.9131752, longitude: -77.0324047), name: "Mapbox")
        let destination = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 38.8977, longitude: -77.0365), name: "White House")

        // Set options
        let options = NavigationRouteOptions(waypoints: [origin, destination])

        // Request a route using MapboxDirections.swift
        Directions.shared.calculate(options) { (waypoints, routes, error) in
            guard let route = routes?.first else { return }
            // Pass the generated route to the the NavigationViewController
            viewController = NavigationViewController(for: route)
            viewController.modalPresentationStyle = .fullScreen

        }
        return viewController
    }

    func updateUIViewController(_ uiViewController: NavigationViewController, context: Context) {

    }
}

谢谢你给我指明了正确的方向。我遇到了另一个问题,也许你愿意帮助我解决这个问题,这与本文相关: