我有一些问题需要理解,为什么来自导入(和复杂)的Objective-C接口的一些成员函数在Swift中不可用。
我有一个Bridging-Header文件:
#import "EvernoteSDK.h"
我无法在ViewController中使用某些成员函数
let userStore = EvernoteUserStore()
userStore.initWithSession(session)
initWithSession不适用于swift代码,但为什么?
objective-C标题显示:
@interface EvernoteUserStore : ENAPI
+ (instancetype)userStore;
- (id)initWithSession:(EvernoteSession *)session;
如果我可以查看暴露的Objective-C标题,我可能会理解,修剪工作原理
答案 0 :(得分:1)
在Swift中,初始化程序调用与构造函数组合在一起。换句话说,Objective-C'
EvernoteUserStore *userStore = [[EvernoteUserStore alloc] initWithSession:session];
变为
let userStore = EvernoteUserStore(session:session);
该工具识别Objective-C的initWithSomething:
名称,并将其转换为
init(something something : SomeType)
如果是EvernoteUserStore
,则相应的init
方法如下所示:
init(session session: EvernoteSession!)