- (id)来自Swift的Obj-C Lib?

时间:2014-06-06 01:29:47

标签: ios xmpp swift xmppframework

起初,我对Obj-C非常苛刻(不喜欢语法),但现在我喜欢用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

1 个答案:

答案 0 :(得分:1)

尝试在Swift中初始化它:

var jabberRosterStorage: XMPPCoreDataStorage, XMPPRosterStorage = XMPPCoreDataStorage()

var jabberRoster: XMPPRoster = XMPPRoster(rosterStorage: jabberRosterStorage)

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

Reference