How to use ORKESerializer in my app?

余生颓废 提交于 2019-12-12 03:27:00

问题


I am working on developing my first ResearchKit App. I have been watching this video. One of the techniques used that is going to be helpful for me is serializing the results of a survey to JSON. The method used in the video is ORKESerializer.JSONDataForObject(taskResult). He explains that this is not a standard part of researchKit, but it was included in a test app, called ORKTest that is on GitHub.

I set up my taskViewController delegate just like he had it set on the video, like this:

extension ViewController : ORKTaskViewControllerDelegate {

    func taskViewController(taskViewController: ORKTaskViewController, didFinishWithReason reason: ORKTaskViewControllerFinishReason, error: NSError?) {
        switch reason {
        case .Completed:
            let taskResult = taskViewController.result

            let jsonData = try! ORKESerializer.JSONDataForObject(taskResult)
            if let jsonString = NSString(data: jsonData, encoding: NSUTF8StringEncoding) {
                print(jsonString)
            }
            break

        case .Failed, .Discarded, .Saved:
            break

        }
        //Handle results with taskViewController.result
//        let taskResult = taskViewController.result
        taskViewController.dismissViewControllerAnimated(true, completion: nil)
    }

}

I am getting this error upon compiling : use of unresolved identifier: ORKESerializer

So in the ORKTest app, in the GitHub files, I found 2 files. One called ORKESerialization.h, and one called ORKESerialization.m. I tried dragging those into my project, as I saw those files in the man's project in the video. And then that also prompted me to create a bridging header file as well, which I also saw in his project.

After doing that I am still getting the same error. The truth is I don't know exactly how to include these serialization packages with my app. Does anyone know how to included the right files so that I can implement this ORKEserialization method?

Thanks!


回答1:


You need to import ORKESerialization.h in your bridging header:

  #import "ORKESerialization.h"


来源:https://stackoverflow.com/questions/36225543/how-to-use-orkeserializer-in-my-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!