自 Swift 2.2 起无法访问 extern NSString [英] extern NSString not accessible since Swift 2.2
问题描述
自从使用 Swift 2.2 更新到 Xcode 7.3 后,我无法从外部 Objective-C 库访问变量.
Since the update to Xcode 7.3 with Swift 2.2 I am not able to access variables from an external Objective-C Library.
从今天开始我就可以访问这个变量了:
Since today I was able to access this variables:
extern NSString* const DEFAULT_URL;
这是在来自预编译的 .a 框架的 Objective-C 头文件中定义的.
This is defined in an Objective-C Header file from a precompiled .a framework.
在我的 swift 代码中,我只需要调用 DEFAULT_URL
.
In my swift code I only had to call DEFAULT_URL
.
从 Swift 2.2 开始,我收到以下错误:
Since Swift 2.2 I get the following errror:
Use of unresolved identifier 'DEFAULT_URL'
我可以访问这个框架的类和方法,但是我不能访问extern NSStrings
.
I am able to access the classes and methods of this framework, but I can't access extern NSStrings
.
任何想法如何解决这个问题?
Any ideas how to fix this?
推荐答案
@patrickS 我有一个愚蠢的原因,我的 extern const 是在我的 .h 文件中的 @interface 中定义的.这似乎使它成为这个版本的 XCode/Clang 的 Swift 代码私有的.它适用于所有 extern consts,而不仅仅是 NSString *.
@patrickS I had this for a silly reason, my extern const was defined inside an @interface in my .h file. This seems to have made it private to Swift code with this version of XCode / Clang. It applies to all extern consts not just NSString *.
例如
//In Foo.h
extern const int kBlah
@interface Foo
...
@end
代替
//In Foo.h
@interface Foo
extern const int kBlah
...
@end
这篇关于自 Swift 2.2 起无法访问 extern NSString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!