Presenting ResearchKit Survey from SwiftUI View

I am trying to present my ResearchKit Survey from a SwiftUI view. Before I moved my home screen to a SwiftUI view, I would present my survey using:

let taskViewController = ORKTaskViewController(task: SurveyTask.surveyTask, taskRun: nil)
taskViewController.delegate = self
present(taskViewController, animated: true, completion: nil)

I was able to present the SwiftUI from a UIKit view controller using:

let mainHomeScreenSwUI = UIHostingController(rootView: MainHomeScreen())
mainHomeScreenSwUI.modalPresentationStyle = .fullScreen
present(mainHomeScreenSwUI, animated: true, completion: nil)

but now I would like to present my taskViewController from my SwiftUI view. I would like to open the survey from the press of a button like below.

Button("Take Survey \(recentFriday ?? "01/01")") {
              //open survey
              let taskViewController = ORKTaskViewController(task: SurveyTask.surveyTask, taskRun: nil)
              taskViewController.delegate = self
              present(taskViewController, animated: true, completion: nil)
            }

This causes an error.

Any help would be greatly appreciated!

I was able to figure out how to present the survey, however, now the survey does not dismiss.

I had to make another swift file which connects the ORKTaskViewController.

import SwiftUI
import ResearchKit

struct SurveyView: UIViewControllerRepresentable{
  func makeUIViewController(context: Context) -> ORKTaskViewController{
    let config = ORKTaskViewController(task: SurveyTask.surveyTask, taskRun: nil)
    return config
  }
  func updateUIViewController(_ uiVIewController: ORKTaskViewController, context: Context){
     
  }
  typealias UIViewControllerType = ORKTaskViewController
   
   
}

Adding this line to the home screen SwiftUI @State private var showingSurvey = false. Making showingSurvey=true as the action to the button click, with this at the end of the VBox to present the survey. .sheet(isPresented: $showingSurvey){SurveyView()}

If anyone knows how to get the survey to dismiss, please reply.

Presenting ResearchKit Survey from SwiftUI View
 
 
Q