0

I am converting a project to Swift 3 and am having a similar issue to Swift 3 ObjC Optional Protocol Method Not Called in Subclass for the Core Bluetooth peripheral methods.

Instance method 'peripheral(:didDiscoverServices:)' nearly matches optional requirement 'peripheral(:didDiscoverServices:)' of protocol 'CBPeripheralDelegate'

However, when I add the @objc declaration as a workaround, I am getting this error:

Method cannot be marked @objc because the type of the parameter 2 cannot be represented in Objective-C

This is my declaration:

@objc(peripheral:didDiscoverServices:)
func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {

I am using Xcode 8.3.1

Any ideas?

Community
  • 1
  • 1
charliework
  • 33
  • 10
  • The problem is that `Error` is an enum, and Objective-C can't handle optional enums. I'm not sure how to work around it though. – John Montgomery May 03 '17 at 19:19
  • 1
    Your code compiles for me, even without the `@objc`. Can you post a self-contained example demonstrating the problem? – Martin R May 03 '17 at 19:21
  • @JohnMontgomery: I don't think that is the problem. Swift bridges between `Error` and `NSError`. See https://developer.apple.com/reference/corebluetooth/cbperipheraldelegate/1518744-peripheral and switch between Swift and Objective-C. – Martin R May 03 '17 at 19:22
  • 1
    It seems the issue was that Error was extended, which was causing the first error and preventing the objc bridging from working properly. – charliework May 04 '17 at 13:35

0 Answers0