Skip to content

Instantly share code, notes, and snippets.

@Kdan
Last active January 24, 2021 19:07
Show Gist options
  • Save Kdan/912f29ea6e876b18d76b249c87d8ed97 to your computer and use it in GitHub Desktop.
Save Kdan/912f29ea6e876b18d76b249c87d8ed97 to your computer and use it in GitHub Desktop.
/// Facade for the CBCentralManagerDelegate.
protocol CentralManagerDelegate: CBCentralManagerDelegate {
/// Function called when the central manager updates its state.
func centralManagerDidUpdateState(_ central: CentralManager)
/// Function called when the central manager discovers peripherals.
func centralManager(_ central: CentralManager,
didDiscover peripheral: Peripheral,
advertisementData: [String : Any],
rssi RSSI: NSNumber)
}
/// Wishful thinking...
/// This is unfortunately not possible due to the inherited objective-c exposure requirement from the CBCentralManagerDelegate file.
extension CentralManagerDelegate {
func centralManagerDidUpdateState(_ central: CBCentralManager) {
centralManagerDidUpdateState(central as CentralManager)
}
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
centralManager(central as CentralManager,
didDiscover: peripheral as Peripheral,
advertisementData: advertisementData,
rssi: RSSI)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment