I've implemented a class that lets you check out whether there is an ApplePencil connected to the device or not.import Foundationimport CoreBluetoothclass ApplePencilReachability: NSObject {    fileprivate let centralManager = CBCentralManager()    var pencilReachabilityDidChangeClosure:((_ isAvailable: Bool) -> Void)?    var isPencilReachable = false    var timer: Timer?    convenience init(didChangeClosure:@escaping ((_ isAvailable: Bool) -> Void)) {        self.init()        centralManager.delegate = self        pencilReachabilityDidChangeClosure = didChangeClosure    }    @objc fileprivate func checkReachability() {        let peripherals = centralManager.retrieveConnectedPeripherals(withServices: [CBUUID(string: 180A)])        let wasPencilReachable = isPencilReachable        isPencilReachable = peripherals.contains(where: isApplePencil)        if wasPencilReachable != isPencilReachable {            pencilReachabilityDidChangeClosure?(isPencilReachable)        }        if isPencilReachable {            timer?.invalidate()        }    }    fileprivate func isApplePencil(peripheral: CBPeripheral) -> Bool {        return peripheral.name == Apple Pencil    }}// MARK: CBCentralManagerDelegateextension ApplePencilReachability: CBCentralManagerDelegate {    func centralManagerDidUpdateState(_ central: CBCentralManager) {        if central.state == .poweredOn {            timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(checkReachability), userInfo: nil, repeats: true)        }        else {            timer?.invalidate()            pencilReachabilityDidChangeClosure?(false)        }    }}It really like to get some tipps to improve this class and make it more 'swifty', if possible :)This class is also available open-source on Github so feel free to submit Pull-Requests for improvements :)While writing this class I was inspired by HAS' answer on StackOverflow on this topic.
Swift class to check ApplePencil reachability
swift;ios;bluetooth