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!