MacOS - A C function pointer cannot be formed from a closure that captures context

Hi, posting in iOS because there's no macOS option.

I'm using the MetaTracker, and have set up everything in the macOS starter project as per the instructions in the Swift tutorial to be able to receive the data. I was able to connect the sensor and everything, and have it stream data outputted to the console, but I've been unable to do anything with the data because if I try and do anything other than just print it, I get the error "A C function pointer cannot be formed from a closure that captures context"

@IBAction func startPressed(_ sender: Any) {
    let board = device.board
    guard mbl_mw_metawearboard_lookup_module(board, MBL_MW_MODULE_ACCELEROMETER) != MODULE_TYPE_NA else{
        print("No accelerometer")
        return
        }
    let signal = mbl_mw_acc_get_acceleration_data_signal(board)

    mbl_mw_datasignal_subscribe(signal, bridge(obj: self)) { (context, data) in
        let _: NextViewController = bridge(ptr: context!)
        let obj: MblMwCartesianFloat = data!.pointee.valueAs()
        if (obj.x>0.2||obj.y>0.2){
            print(obj.x, obj.y, obj.z)
            self.adding(obj.x, obj.y, obj.z)
            }
        }
    mbl_mw_acc_enable_acceleration_sampling(board)
    mbl_mw_acc_start(board)
}

it works fine if I remove the line self.adding(obj.x, obj.y, obj.z) but I'm not sure how i'm supposed to use the data otherwise

Any help would be greatly appreciated, thanks!

Comments

Sign In or Register to comment.