简体   繁体   English

如何导入Objective-C ++文件

[英]how to import objective-c++ file

I'm having trouble including a .mm file in my cocoa project. 我在可可项目中包含.mm文件时遇到麻烦。 The .mm file #includes the .cpp file. .mm文件#包括.cpp文件。 If I don't #import the project builds fine. 如果我不#import,则项目构建良好。 However, I need to #import the .mm file but when I do, I get 'string' file not found. 但是,我需要#import .mm文件,但是当我这样做时,找不到“字符串”文件。 How do I use the mm file without getting that error? 如何使用mm文件而不出现该错误?

Here is a link to the project 这是项目的链接

Don't use #import with a .mm file. 不要将#import与.mm文件一起使用。 Move its public interface into a .h file and import that where you need it. 将其公共接口为.h文件,并导入在你需要它。

Turns out I needed to move the part of the interface that defines the cpp ivar to the implementation file CPPWrapper.mm 原来,我需要将定义cpp ivar的接口部分移至实现文件CPPWrapper.mm

@interface CPPWrapper ()
@property (nonatomic, readwrite, assign) Cpp *cpp;
@end

@implementation CPPWrapper
@synthesize cpp = _cpp;
//do stuff with cpp ivar here
@end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM