Download sensor data as a csv file
Hello, I am developing the sensor logging iOS application. I want to make the data stored in the sensor download as a csv file when the user presses the button on the screen. I tried to implement such function in the "mbl_mw_logger_subscribe" as below.
mbl_mw_logger_subscribe(logger, bridge(obj: self)) { (context, obj) in
let acceleration: MblMwCartesianFloat = obj!.pointee.valueAs()
let fileManager = FileManager.default
let documentURL = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0]
let fileURL = documentURL.appendingPathComponent("accelerometer.csv")
var accelLog: NSString = ""
...}
However, I realized that this would not work because the file would be initialized each time the closure was called. I should define them outside the closure, but if I do that, the error, "A C function pointer cannot be formed from a closure that captures context" occurs.
How can I solve this? Or is there any other way to implement this function?
Comments
Take a look at this thread that shows how to create bridges: https://mbientlab.com/community/discussion/2945/macos-a-c-function-pointer-cannot-be-formed-from-a-closure-that-captures-context#latest
This isn't really metawear api centric, just a general swift coding question so you might want to look on stackoverflow for more information.
Thank you! It was very helpful.