目标C到具有多个目标的Swift头文件 [英] Objective C to Swift header file with multiple targets

查看:78
本文介绍了目标C到具有多个目标的Swift头文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已通过导入语句成功从Objective C(针对目标"MyApp")调用了我的Swift类:

I'm successfully calling my Swift classes from Objective C (for target 'MyApp') via the import statement:

#import "MyApp-Swift.h"

我现在创建了一个名为"MyAppLite"的新目标

I've now created a new target called "MyAppLite"

当我编译新目标时,由于代码需要"MyApp-Swift.h",但是编译器正在创建"MyAppLite-Swift.h",我会收到错误消息.

When I compile the new target, I get errors because "MyApp-Swift.h" is required by the code, but the compiler is creating "MyAppLite-Swift.h"

因此,我需要为要编译的目标创建条件Swift/ObjC标头#import.

So, I need to create a conditional Swift/ObjC header #import for the target I'm compiling against.

这怎么办?还是有更好的方法?

How can this be done, or is there a better way?

推荐答案

还可以将Build Settings中的Product Module Name设置设置为跨模块相同(我将其设置为$(PROJECT_NAME)),因此所生成的<project>-Swift.h文件在所有模块中都具有相同的名称.这消除了添加/检查预处理器宏的需要.

It is also possible to set the Product Module Name setting in Build Settings to be the same across your modules (I set it to $(PROJECT_NAME)), so that the <project>-Swift.h file that is generated has the same name across all modules. This eliminates the need for adding/checking preprocessor macros.

这篇关于目标C到具有多个目标的Swift头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆