在Swift中将字典对象传递给Objective C协议 [英] Passing dictionary objects to Objective C protocol in Swift
问题描述
我正在尝试使用swift将字典对象传递给Objective C协议.
I'm trying to pass a dictionary object to an Objective C protocol using swift.
协议代码段如下:
@protocol MessageDelegate
- (void)handleNewMessageArrived:(NSDictionary *)messageContent;
@end
这是实现协议的swift类:
and this is the swift class the implements the protocol:
class ViewController: UIViewController, MessageDelegate
{
...
func handleNewMessageArrived(messageContent : NSDictionary!)
{
...
}
}
但是构建失败,并且我得到的错误是:
But the build fails, and the error I get is:
" 类型'ViewController'不符合协议'MessageDelegate "
"the type 'ViewController' does not conform to protocol 'MessageDelegate"
我查看了此SO问题,但它处理的是特定对象类型.
I looked at this SO Question but it deals with a specific object type.
我声明\实现委托方法的方式是否存在错误?还是以我认为参数被快速映射的方式?
is there an error in the way I declare\implement the delegate method? or in the way I assume the arguments are mapped in swift?
我是Swift的新手,所以非常感谢您的帮助.
I'm new to Swift so any Help will be much appreciated.
推荐答案
尝试在您的Swift类中实现该方法,如下所示:
Try implementing the method in your Swift class like this:
func handleNewMessageArrived(messageContent: [NSObject : AnyObject]!) {
// Handle the message
}
这篇关于在Swift中将字典对象传递给Objective C协议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!