| 123456789101112131415161718192021222324252627282930313233343536 |
- //
- // CBPeripheral.swift
- // xDripG5
- //
- // Copyright © 2017 LoopKit Authors. All rights reserved.
- //
- import CoreBluetooth
- // MARK: - Discovery helpers.
- extension CBPeripheral {
- func servicesToDiscover(from serviceUUIDs: [CBUUID]) -> [CBUUID] {
- let knownServiceUUIDs = services?.compactMap({ $0.uuid }) ?? []
- return serviceUUIDs.filter({ !knownServiceUUIDs.contains($0) })
- }
- func characteristicsToDiscover(from characteristicUUIDs: [CBUUID], for service: CBService) -> [CBUUID] {
- let knownCharacteristicUUIDs = service.characteristics?.compactMap({ $0.uuid }) ?? []
- return characteristicUUIDs.filter({ !knownCharacteristicUUIDs.contains($0) })
- }
- }
- extension Collection where Element: CBAttribute {
- func itemWithUUID(_ uuid: CBUUID) -> Element? {
- for attribute in self {
- if attribute.uuid == uuid {
- return attribute
- }
- }
- return nil
- }
- }
|