Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Xcode 13 SDK without breaking previous versions #50

Merged
merged 1 commit into from
Jul 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions CoreBluetoothMock/Classes/CBMCentralManagerNative.swift
Original file line number Diff line number Diff line change
Expand Up @@ -381,22 +381,22 @@ public class CBMPeripheralNative: CBMPeer, CBMPeripheral {

/// Returns the wrapper for the native CBService.
/// - Parameter service: The native service.
private func mock(of service: CBService) -> CBMServiceNative? {
private func mock(of service: CBService?) -> CBMServiceNative? {
return impl.mockServices?.first { $0.service == service }
}

/// Returns the wrapper for the native CBCharacteristic.
/// - Parameter characteristic: The native characteristic.
private func mock(of characteristic: CBCharacteristic) -> CBMCharacteristicNative? {
let service = mock(of: characteristic.service)
private func mock(of characteristic: CBCharacteristic?) -> CBMCharacteristicNative? {
let service = mock(of: characteristic?.service)
return (service?._characteristics as? [CBMCharacteristicNative])?
.first { $0.characteristic == characteristic }
}

/// Returns the wrapper for the native CBDescriptor.
/// - Parameter descriptor: The native descriptor.
private func mock(of descriptor: CBDescriptor) -> CBMDescriptorNative? {
let characteristic = mock(of: descriptor.characteristic)
private func mock(of descriptor: CBDescriptor?) -> CBMDescriptorNative? {
let characteristic = mock(of: descriptor?.characteristic)
return (characteristic?._descriptors as? [CBMDescriptorNative])?
.first { $0.descriptor == descriptor }
}
Expand All @@ -405,7 +405,7 @@ public class CBMPeripheralNative: CBMPeer, CBMPeripheral {
/// - Parameters:
/// - service: The native service.
/// - action: The action to perform on its mock.
private func usingMock(of service: CBService,
private func usingMock(of service: CBService?,
action: @escaping (CBMPeripheral, CBMPeripheralDelegate, CBMService) -> ()) {
if let delegate = impl.delegate,
let serviceMock = mock(of: service) {
Expand All @@ -417,9 +417,9 @@ public class CBMPeripheralNative: CBMPeer, CBMPeripheral {
/// - Parameters:
/// - service: The native characteristic.
/// - action: The action to perform on its mock.
private func usingMock(of characteristic: CBCharacteristic,
private func usingMock(of characteristic: CBCharacteristic?,
action: @escaping (CBMPeripheral, CBMPeripheralDelegate, CBMCharacteristic) -> ()) {
usingMock(of: characteristic.service) { p, d, s in
usingMock(of: characteristic?.service) { p, d, s in
if let characteristicMock = self.mock(of: characteristic) {
action(p, d, characteristicMock)
}
Expand All @@ -430,9 +430,9 @@ public class CBMPeripheralNative: CBMPeer, CBMPeripheral {
/// - Parameters:
/// - service: The native descriptor.
/// - action: The action to perform on its mock.
private func usingMock(of descriptor: CBDescriptor,
private func usingMock(of descriptor: CBDescriptor?,
action: @escaping (CBMPeripheral, CBMPeripheralDelegate, CBMDescriptor) -> ()) {
usingMock(of: descriptor.characteristic) { p, d, c in
usingMock(of: descriptor?.characteristic) { p, d, c in
if let descriptorMock = self.mock(of: descriptor) {
action(p, d, descriptorMock)
}
Expand Down