Skip to content

Instantly share code, notes, and snippets.

@below
Last active June 10, 2021 14:07
Show Gist options
  • Save below/cb27c0d1ccdbdae3b27a73c0414afcd2 to your computer and use it in GitHub Desktop.
Save below/cb27c0d1ccdbdae3b27a73c0414afcd2 to your computer and use it in GitHub Desktop.
import CoreBluetooth
class Test: NSObject, CBPeripheralManagerDelegate {
func peripheralManager(_ peripheral: CBPeripheralManager, didAdd service: CBService, error: Error?) {
let peripheral: CBPeripheral
// So what I would like is something like this
// But this does not work :(
if #available(iOS 15, *) {
guard let nonOptional = service.peripheral else {
return
}
peripheral = nonOptional
} else {
peripheral = service.peripheral
}
let result: CBPeripheral = peripheral
print ("\(result)")
}
func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment