Skip to content

Instantly share code, notes, and snippets.

@Kdan
Last active January 24, 2021 19:33
Show Gist options
  • Save Kdan/e2a0ae486f5b593a6ac485f67323274e to your computer and use it in GitHub Desktop.
Save Kdan/e2a0ae486f5b593a6ac485f67323274e to your computer and use it in GitHub Desktop.
/// A Facade for the CBCentralManager.
protocol CentralManager {
/// The delegate of the central manager.
var delegate: CBCentralManagerDelegate? { get set }
/// The state of the central manager.
var state: CBManagerState { get }
/// Call this function to scan for bluetooth peripherals.
func scanForPeripherals(withServices serviceUUIDs: [CBUUID]?)
/// Connect to a peripheral.
func connect(_ peripheral: Peripheral, options: [String : Any]?)
}
extension CBCentralManager: CentralManager {
func connect(_ peripheral: Peripheral, options: [String : Any]?) {
guard let peripheral = peripheral as? CBPeripheral else { fatalError() }
connect(peripheral, options: nil)
}
}
/// A Facade for the CBPeripheral.
protocol Peripheral {
/// The name of the peripheral
var name: String? { get }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment