I'm new to Swift. Making a pet project that works with Bluetooth Low Energy (BLE) devices. Thanks to Google found out how to run it (scan, connect etc). But still don't understand how it exactly works. The code is next:
class BLEManager: CBCentralManagerDelegate, OtherProtocols {
private var myCentral: CBCentralManager!
override init() {
super.init()
myCentral = CBCentralManager(delegate: self, queue: nil)
myCentral.delegate = self
}
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
// This one discover devices
}
func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
// This one handles connection
}
func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?) {
// Does some stuff as well
}
}
The question is why do these methods have the same name? I see that they have different parameters (with pretty clear naming), but how Swift knows which method to call?
P.s. Maybe it doesn't fit my perception model because of JS background. Anyway, much appreciate any help