– (id)从Obj-C Lib在Swift中?

起初,我在Obj-C非常糟糕(不喜欢语法),但现在用Swift我爱iPhone开发:D

这里是我的问题,我尝试使用Obj-C库(xmppframework),但是当我尝试初始化XMPPRoster所需的方法不可用…

Objective-C用法:

xmppRosterStorage = [[XMPPRosterCoreDataStorage alloc] initWithInMemoryStore]; xmppRoster = [[XMPPRoster alloc] initWithRosterStorage:xmppRosterStorage]; 

但在我的Swift类的方法“initWithRosterStorage”是不可用:(

迅速:

 var jabberRosterStorage: XMPPCoreDataStorage = XMPPCoreDataStorage() var jabberRoster:XMPPRoster = XMPPRoster(....) 

XMPPRoster.m:

 - (id)initWithRosterStorage:(id <XMPPRosterStorage>)storage { return [self initWithRosterStorage:storage dispatchQueue:NULL]; } 

也许Swift有(id)的问题,因为在Swift中,我认为它现在是AnyObject

尝试在Swift中像这样初始化它:

 var jabberRosterStorage: XMPPCoreDataStorage, XMPPRosterStorage = XMPPCoreDataStorage() var jabberRoster: XMPPRoster = XMPPRoster(rosterStorage: jabberRosterStorage) 

Swift会将[[Class alloc] initWithVar:variable]Class(var: variable)

参考