I am trying to use surveys from ResearchKit. However, I'm getting a selector instance error when I am trying to present the taskViewController. I followed the example on the documentation and don't know why I'm getting an error. My framework is installed from Cocoapods (ResearchKit 2.0.0)
import UIKit
import ResearchKit
class ViewController: UIViewController, ORKTaskViewControllerDelegate {
func taskViewController(_ taskViewController: ORKTaskViewController, didFinishWith reason: ORKTaskViewControllerFinishReason, error: Error?) {
let taskResult = taskViewController.result
// You could do something with the result here.
// Then, dismiss the task view controller.
dismiss(animated: true, completion: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let myStep = ORKInstructionStep(identifier: "intro")
myStep.title = "Welcome to ResearchKit"
let task = ORKOrderedTask(identifier: "task", steps: [myStep])
let taskViewController = ORKTaskViewController(task: task, taskRun: nil)
taskViewController.delegate = self
present(taskViewController, animated: true, completion: nil)
}
}
The error is:
libc++abi: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[testResearchKit.AppDelegate window]: unrecognized selector sent to instance 0x6000031980b0'
terminating with uncaught exception of type NSException
CoreSimulator 757.5 - Device: iPhone SE (2nd generation) (8C24E83B-05CA-434B-84EF-ADAF742E67B0) - Runtime: iOS 14.5 (18E182) - DeviceType: iPhone SE (2nd generation)