-1

Feeling pretty stupid because I had a very similar question not too long ago:

init CBCentralManager: Type of expression is ambiguous without more context

This time I'm instantiating a CBPeripheralManager inside viewDidLoad to an iVar (attempted both 'lazy' and '!' modifiers).

I've conformed to the delegate (both on type and as an extension), but I still get the same error when I try to assign self instead of nil for the delegate parameter.

class vc: UIViewController {
    var peripheralManager: CBPeripheralManager!

    override func viewDidLoad() {
        super.viewDidLoad()            
        peripheralManager = CBPeripheralManager(delegate: self, queue: nil)
    }
}

extension vc: CBPeripheralDelegate { }

How do I get self as an instance here, or whatever is the actual issue?

Mercutio
  • 1,152
  • 1
  • 14
  • 33

1 Answers1

3

Your extension is conforming to the wrong protocol.

Change:

extension vc: CBPeripheralDelegate

to:

extension vc: CBPeripheralManagerDelegate

And then you must implement at least the minimum required protocol methods.

rmaddy
  • 314,917
  • 42
  • 532
  • 579