ios - 我有办法快速查看公开的 Objective-C header

标签 ios swift evernote bridge

我有问题要理解,为什么 Swift 中无法使用一组导入的(复杂的)Objective-C 接口(interface)的一些成员函数。

我有一个桥接头文件:

#import "EvernoteSDK.h"

而且我不能在我的 ViewController 中使用一些成员函数

let userStore = EvernoteUserStore()
userStore.initWithSession(session)

initWithSession 不适用于 swift 代码,但为什么?

Objective-C header 显示:

@interface EvernoteUserStore : ENAPI
+ (instancetype)userStore;
- (id)initWithSession:(EvernoteSession *)session;

如果我可以查看公开的 Objective-C header ,我可能会理解该重整是如何工作的

最佳答案

在 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!)

关于ios - 我有办法快速查看公开的 Objective-C header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24218811/

相关文章:

ios - 无法在图像之间滚动

ios - 使用 uiview 在 CollectionView 中上拉重新加载

ios - 如何在编辑表格 View 单元格中的文本字段时重新加载所有表格 View 单元格 - iOS Swift

ssl - Evernote PHP API 和 cURL SSL 连接失败

emacs - 我的印象笔记模式现在不能用了

javascript - 我正在尝试使用 XSLT 转换 Evernote 的 ENMLinto markdown,并且 node_xslt 提示未知标签和实体

ios - 无法在设备上运行单元测试 - 代码覆盖数据生成失败 (IOS)

ios - 防止在 iOS 6 上旋转 ABPerson ViewController 和 ABNewPerson ViewController

json - 无法解码 JSON - 期望解码 Int 但发现了字符串/数据

ios - GCDAsyncSocket - 如何写入可变数据?