从Swift访问extern const struct
我无法从Swift中使用Mogenerator生成的c-struct。
该结构在实现中:
const struct MyAttributes MyAttributes = { .foo = @"foo", };
然后在标题中:
extern const struct MyAttributes { __unsafe_unretained NSString *foo; } MyAttributes;
我将头导入添加到桥头。 但是我不能从Swift访问结构。 用Objective CI可以。 我想也许Swift需要结构声明,因为它是在实现文件中,所以我试图将.m文件添加到桥接头,但这是行不通的。 我想我不能改变这些文件的结构,因为它们是由Mogenerator生成的。
我该如何解决?
谢谢。
同
#import "YourClass.h"
在桥接头文件中,你可以从Swift中访问结构体
let fooAttr = MyAttributes.foo println(fooAttr) // Output: "foo"