0

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.

shows files included in my 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!

jeffery_the_wind
  • 17,048
  • 34
  • 98
  • 160

1 Answers1

2

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

  #import "ORKESerialization.h"
jwe
  • 436
  • 2
  • 4
  • Hi, I just ran into an issue. Your solution here worked for running my project in the simulator and printing JSON strings to the console output, but now I am getting 3 errors related to the `.m` file from this package when archiving the app for a generic iOS device. errors:`clang: error: linker command failed with exit code 1 (use -v to see invocation)`, ` "_OBJC_CLASS_$_ORKLocation", referenced from:`, ` "_OBJC_CLASS_$_ORKConfirmTextAnswerFormat", referenced from:`. Any help would be greatly appreciated! – jeffery_the_wind Mar 28 '16 at 15:17
  • sorry, this is the full error: `Undefined symbols for architecture arm64: "_OBJC_CLASS_$_ORKLocation", referenced from: objc-class-ref in ORKESerialization.o "_OBJC_CLASS_$_ORKConfirmTextAnswerFormat", referenced from: objc-class-ref in ORKESerialization.o ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)` – jeffery_the_wind Mar 28 '16 at 15:22