0

I have been struggling to implement kalman-ios into my Swift project. The kalman-ios project is written entirely in Objective-C++.

I recently learned how to call Objective-C++ functions from this video guide

Issue

My issue is that I can make calls to normal functions, but none that are within an @implementation. Ex: I cannot successfully bridge Swift to didReadAccelerometer

@interface KFAppDelegate ()
...
- (void)didReadAccelerometer:(CMAccelerometerData *)data;

@implementation KFAppDelegate
...
- (void)didReadAccelerometer:(CMAccelerometerData *)data
{
    //  gyro or compass data not available yet, wait until next update
    if (!self.gyroData || !self.magnetometerData)
        return;
    self.accelData = data;

    //  run filter
    [self performKalmanUpdate];

    //  send state to server
    [self transmitState];

    //  discard old data
    self.accelData = nil;
    self.gyroData = nil;
}

I can successfully bridge Swift to getTime as it is not inside an @implementation

double getTime()
{
    // mach_absolute_time() returns billionth of seconds
    const double kOneBillion = 1000000000.0;
    return getTime_ns() / kOneBillion;
}

With bridging header file that contains:

#ifdef __cplusplus
extern "C" {
#endif

double getTime();

#ifdef __cplusplus
}
#endif

I need to get at the functions within @implementation because they use class-level variables throughout.

Is there a way to use these functions in Swift?

Thank you for any help you can provide!

Ian
  • 113
  • 1
  • 6
  • Well, where's your Swift code? – Alexander Mar 01 '20 at 17:17
  • you will have to create wrapper converting from objc++ to objc and then use swift-objc interop. See this question: https://stackoverflow.com/questions/32541268/can-i-have-swift-objective-c-c-and-c-files-in-the-same-xcode-project – timbre timbre Mar 01 '20 at 17:35
  • 1
    All you need is add the method to the header file. If it's not in the header file, it cannot be called from outside the source file, not in Swift, not in Objective-C or C++. – gnasher729 Mar 01 '20 at 19:49

0 Answers0