我无法从 Swift 访问用 Mogenerator 生成的 c 结构。
结构在实现中:
const struct MyAttributes MyAttributes = {
.foo = @"foo",
};
然后在标题中:
extern const struct MyAttributes {
__unsafe_unretained NSString *foo;
} MyAttributes;
我将 header 导入添加到桥接 header 中。但我无法从 Swift 访问该结构。使用 Objective C 我可以。我想也许 Swift 需要结构声明,因为它在实现文件中,所以我尝试将 .m 文件添加到桥接 header ,但这不起作用。我想我无法更改这些文件的结构,因为它们是由 Mogenerator 生成的。
我该如何解决这个问题?
谢谢。
最佳答案
与
#import "YourClass.h"
在桥接头文件中,您可以从 Swift 访问该结构 as
let fooAttr = MyAttributes.foo
println(fooAttr) // Output: "foo"
关于ios - 从 Swift 访问 extern const struct,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27365150/