Swift protocol delegate returning nil

DisplayName

I set a breakpoint in the didConnect function to print out the value of delegate, and it is coming back as nil and I have not clue why

@objc protocol KestrelDeviceConnectDelegate {
    func didConnect()
    func didDisconnect()
}

@objcMembers
class KestrelDeviceConnect: NSObject{


    static let singleton = KestrelDeviceConnect()
    public weak var delegate: KestrelDeviceConnectDelegate?

func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
        self.isInitialReading = false
        self.kestrelIsConnected = true
        kestrelPeripheral.discoverServices(nil)
        delegate?.didConnect()

    }

}

in viewDidLoad in my destination VC

_kestrelVC = [[KestrelDeviceConnect alloc]init];
[_kestrelVC setDelegate:self];
DisplayName

The problem was initializing a new KestrelDeviceConnect instance, so instead of having _kestrelVC = [[KestrelDeviceConnect alloc]init]; what worked was _kestrelVC = [KestrelDeviceConnect singleton]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related