Question

Is there a say to do this without changing every .m file to .mm?

OK. I am trying to implement the answer but having trouble. Take a look at my Objective C++ .h and .mm below

Objective-C++ - IDCaptureTemplateCommand.h:

#include "Template.h"

@interface IDCaptureTemplateCommand : NSObject
@property (nonatomic, strong) IDCaptureTemplateCommand *IDCaptureTemplateCommand;

@end

Objective-C++ - IDCaptureTemplateCommand.mm:

#include "IDCaptureTemplateCommand.h"

@implementation IDCaptureTemplateCommand

- (id)init
{
    self = [super init];
    if (self) {
        self.captureTemplateCommand = [[IDCaptureTemplateCommand alloc] init];
    }
    return self;
}

@end

Objective-C - IDCameraViewController.h

#import <UIKit/UIKit.h>
#import "IDCaptureTemplateCommand.h"

@interface IDCameraViewController : UIViewController <UINavigationControllerDelegate>

@property (nonatomic) IDCaptureTemplateCommand *captureCommand;  //ERROR - Unknown type name 'IDCaptureTemplateCommand'

@end
Was it helpful?

Solution

You can do so in the same way as you can use C++ from C or whatever. You need to be able to declare the interface using pure Objective-C and then the implementation can be written using Objective-C++.

If your header file uses C++, e.g. your class has an std::string instance variable, then to make the functionality accessible from Objective-C you have to write a wrapper or otherwise hide the C++ at the interface, so that your Objective-C files don't need to see any of the C++ declarations.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top