SwiftUI 协调器:方法无法标记为@objc

SwiftUI Coordinator: method can not be marked @objc

SwiftUI 中使用 UIViewController 我需要为两个按钮分配选择器。那些需要 @objc 但我得到错误:

Method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C

struct ScanPreView: UIViewControllerRepresentable {

    class Coordinator: NSObject {
        
        var parent: ScanPreView
        
        init(_ parent: ScanPreView) {
            self.parent = parent
        }
        
        @objc func dismissPreviewedScanTapped(sender: ScanPreView) {
            
        }
        
        @objc func savePreviewedSceneTapped(sender: ScanPreView) {
            
        }
    }
        
    func makeCoordinator() -> Coordinator {
        Coordinator(self)
    }
    
    func makeUIViewController(context: Context) -> ScenePreviewViewController {
        let preview = ScenePreviewViewController(pointCloud: pointCloud, meshTexturing: meshTexturing, landmarks: nil)
        preview.leftButton.addTarget(context.coordinator, action: #selector(Coordinator.dismissPreviewedScanTapped(sender:)), for: UIControl.Event.touchUpInside)
        preview.rightButton.addTarget(context.coordinator, action: #selector(Coordinator.savePreviewedSceneTapped(sender:)), for: UIControl.Event.touchUpInside)
        return preview
    }
}

你不需要在那里查看,所以如果你需要动作签名,就使用 Any,比如

@objc func dismissPreviewedScanTapped(sender: Any) {
    
}