Configure Logging Tasks Properly

Hello, I am building an iOS application that records and retrieves accelerometer signals.
I have referred to document "" below to make accelerometerStartLog() and accelerometerStopLog(). Below are their code.

func accelerometerStartLog(_ sender: Any) {
    let signal = mbl_mw_acc_bosch_get_acceleration_data_signal(device.board)!
    mbl_mw_datasignal_log(signal, bridge(obj: self)) { (context, logger) in
        let _self: DeviceDetailViewController = bridge(ptr: context!)
        let cString = mbl_mw_logger_generate_identifier(logger)!
        let identifier = String(cString: cString)
        _self.loggers[identifier] = logger!
    mbl_mw_logging_start(device.board, 0)

func accelerometerStopLog(_ sender: Any) {
    guard let logger = loggers.removeValue(forKey: "acceleration") else {
    mbl_mw_logger_subscribe(logger, bridge(obj: self)) { (context, obj) in
        let acceleration: MblMwCartesianFloat = obj!.pointee.valueAs()
    var handlers = MblMwLogDownloadHandler()
    handlers.context = bridgeRetained(obj: self)
    handlers.received_progress_update = { (context, remainingEntries, totalEntries) in
        let _self: DeviceDetailViewController = bridge(ptr: context!)
        let progress = Double(totalEntries - remainingEntries) / Double(totalEntries)
        if remainingEntries == 0 {
            _self.logCleanup { error in
                DispatchQueue.main.async {
                    if error != nil {
    handlers.received_unknown_entry = { (context, id, epoch, data, length) in
    handlers.received_unhandled_entry = { (context, data) in
    mbl_mw_logging_download(device.board, 100, &handlers)

My question is how and where should I define the "loggers" dictionary. I configured it as a class property like "var loggers: [String: OpaquePointer]!" but it didn't work properly. I activated accelerometerStartLog() by clicking the "Start Logging" UIButton after connecting to the board, but the "loggers" dictionary remains nil. In other words, the code inside the closure did not work. Subsequently, when the [Stop Log] button is pressed to invoke the stopLogging() function, of course, an error occurs in the line "guard let logger = self.loggers.removeValue". I already did Xcode debugging but I have no idea how to solve it. How can I do this properly?


Sign In or Register to comment.