是否可以使用Swift& Objective-C代码在同一文件中? [英] Is it possible to have Swift & Objective-C code in the same file?

查看:76
本文介绍了是否可以使用Swift& Objective-C代码在同一文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,在这个大项目中,我正在研究一个带有#Defines URLs的全局头文件。我不能快速使用它们,但为清楚起见,我想在同一.h文件中使用swift替代项,因此,如果曾经更改过一个,则显然应该更改另一个。

For instance in this big project I'm working on there is a "global" header file with #Defines to URLs. I cant use those in swift, but for clarity I want to have the swift alternative in the same .h file so if one is ever changed it should be obvious to change the other.

我希望使用一些编译器魔术,这可能是可能的。

I was hoping with some compiler magic, this might be possible.

推荐答案

不要使用#define-而是使用常量。

Don't use #define -- instead use constants.

Objective-C中的常量

您可以从Swift(使用桥接标头)访问Objective-C常量

You can access Objective-C constants from Swift (using a bridging header)

这篇关于是否可以使用Swift& Objective-C代码在同一文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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