xcode - 自 Swift 2.2 以来无法访问 extern NSString

标签 xcode swift

自从使用 Swift 2.2 更新到 Xcode 7.3 后,我无法从外部 Objective-C 库访问变量。

从今天开始我可以访问这个变量:

extern NSString* const DEFAULT_URL;  

这是在预编译的 .a 框架的 Objective-C 头文件中定义的。

在我的 swift 代码中,我只需调用 DEFAULT_URL

从 Swift 2.2 开始,我得到以下错误:

Use of unresolved identifier 'DEFAULT_URL'  

我可以访问这个框架的类和方法,但是我不能访问extern NSStrings

有什么办法解决这个问题吗?

最佳答案

@patrickS 我有这个是出于一个愚蠢的原因,我的 extern const 是在我的 .h 文件的 @interface 中定义的。这似乎使它对使用此版本的 XCode/Clang 的 Swift 代码私有(private)。它适用于所有外部常量,而不仅仅是 NSString *。

例如

//In Foo.h
extern const int kBlah

@interface Foo
...
@end

代替

//In Foo.h
@interface Foo
extern const int kBlah
...
@end

关于xcode - 自 Swift 2.2 以来无法访问 extern NSString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36148598/

相关文章:

iphone - 显示随机词和用户名

iphone - 在模拟器中第二次运行 ios 应用程序时登录

ios - 如何从 TableView 中删除 Firebase 中的节点

ios - Xcode 单元测试返回没有 'private keyword' 的临时文件夹的 NSURL

ios - 在 UIBarButtonItem 上添加手势

iOS 7 不再与 XCode 4.6.3 一起工作

ios - SwiftyJSON 对象返回字符串

ios - 如何检测 30 秒持续时间

swift - 此用例中的 UILocalizedIndexedCollat​​ion

ios - UICollectionView 每 3 秒自动垂直滚动一次