0

I'm developing an app for iOS with Swift 3 that needing an Objective-C library for connect for a few services. This library has methods that require for a callback function, the method works because in the log of the library I can see that the data is receive.

The problem is the next, when I pass nil to the selector I don't have any problem, but when I put a function I get the next error:

2017-03-08 12:30:51.792 ios-example[1095:15243] *** NSForwarding: warning: object 0x608000227d20 of class 'ios-example.ConnectionSettings' does not implement methodSignatureForSelector: -- trouble ahead
Unrecognized selector -[ios-example.ConnectionSettings performSelectorOnMainThread:withObject:waitUntilDone:]

The code is this:

import Foundation

class ConnectionSettings {

    var _service : ServiceCall?

    @objc func getName(message : StringMessage) {
        print("name : \(message.data)")
    }

    init() {
        self._service = Services.makeService(RB_SERVICE_NAME, 
                                            responseTarget: self, 
                                            selector: #selector(self.getName)))!)
        self._service.send();
    }
}

I think that the problem will be easy to fix it, but I don't know how to do it. Anyone can help me?

Thanks :)

g4s0l1n
  • 114
  • 2
  • 10
  • 1
    why u used two selector `selector: selector:` – Anbu.Karthik Mar 08 '17 at 12:09
  • Try to make ConnectionSettings inherit NSObject http://stackoverflow.com/questions/24415662/object-x-of-class-y-does-not-implement-methodsignatureforselector-in-swift – kennytm Mar 08 '17 at 12:17

1 Answers1

0

The error message tells you the library eventually calls -[ios-example.ConnectionSettings performSelectorOnMainThread:withObject:waitUntilDone:] which is an Objective-C selector defined on NSObject. Your class needs to be a subclass of NSObject

class ConnectionSettings: NSObject { ... }

Edit

The second problem you have is that the object being passed to your getName method does not have a data selector. In fact, it looks like you are being passed a Service object.

JeremyP
  • 84,577
  • 15
  • 123
  • 161
  • Thanks, I solved in part my problem. But now I have another problem, the logs shows the next: Log: 2017-03-08 13:27:09.479 ios-example[2077:37367] -[Service data]: unrecognized selector sent to instance 0x6000002c0380 2017-03-08 13:27:09.488 ios-example[2077:37367] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Service data]: unrecognized selector sent to instance 0x6000002c0380' – g4s0l1n Mar 08 '17 at 12:33
  • @g4s0l1n Added an edit. Note your question has been marked duplicate which it is technically (for the original problem). If you have no joy fixing the new problem, you can create another question. – JeremyP Mar 08 '17 at 13:50
  • I'm fix the problem, the second error if for the syntax of the method that I need to call. Thanks guys :) – g4s0l1n Mar 10 '17 at 11:06