| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- //
- // 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
- }
- func itemWithUUIDString(_ uuidString: String) -> Element? {
- for attribute in self {
- if attribute.uuid.uuidString == uuidString {
- return attribute
- }
- }
- return nil
- }
- }
|