Arnav Patra Arnav Patra - 1 year ago 75
Swift Question

Unable to compile Siri extension in Swift 2.3

I want to integrate the Siri/Intent extension in my App, currently based on Swift 2.3. I am using the Xcode 8 beta 6 build.

The app fails to even compile, giving out errors as

Type 'IntentHandler' does not conform to protocol 'INSendMessageIntentHandling'

Protocol requires function 'handle(sendMessage:completion:)' with type '(sendMessage: INSendMessageIntent, completion: (INSendMessageIntentResponse) -> Void) -> Void'

Objective-C method 'handleWithSendMessage:completion:' provided by method 'handle(sendMessage:completion:)' does not match the requirement's selector ('handleSendMessage:completion:')

Even the sample app from Apple, UnicornChat fails to compile with the same errors. I did change the SWIFT_VERSION flag to Yes, to support Swift 2.3

Sample Code:

func handle(sendMessage intent: INSendMessageIntent, completion: (INSendMessageIntentResponse) -> Void) {
let userActivity = NSUserActivity(activityType: NSStringFromClass(INSendMessageIntent.self))
let response = INSendMessageIntentResponse(code: .Success, userActivity: userActivity)

This fails with the error above.

Anyone has an idea on how to make Siri work in Swift 2.3?

Answer Source

So, this helped

We need to explicitly define the @objc method signatures with the Swift ones. As in the following works.

@objc (handleSendMessage:completion:)
func handle(sendMessage intent: INSendMessageIntent, completion: (INSendMessageIntentResponse) -> Void) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download