1
votes

I'm trying to pass a dictionary object to an Objective C protocol using swift.

the protocol code snippet is as follows:

@protocol MessageDelegate

- (void)handleNewMessageArrived:(NSDictionary *)messageContent;

@end

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:

"the type 'ViewController' does not conform to protocol 'MessageDelegate"

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?

I'm new to Swift so any Help will be much appreciated.

2

2 Answers

7
votes

Try implementing the method in your Swift class like this:

func handleNewMessageArrived(messageContent: [NSObject : AnyObject]!) {
    // Handle the message
}
1
votes

In case of Swift 3, this is what you will need

func handleNewMessageArrived(messageContent: [AnyHashable : Any]!) {
    // Handle the message
}