Trying to scan for Bluetooth
peripherals
using RxBluetoothKit
I get an error
called
"Ambiguous reference to member '==' using this code:
func observeState() -> Observable<[BluetoothState]> {
return manager.observeState()
.startWith(manager.state)
.do(onNext: { print("CHECK POWER", $0) })
.filter{ $0 == .poweredOn }
.take(1)
.do(onNext:{
print("🐦POWERED ON", $0)
})
.flatMap { _ in
self.manager
.scanForPeripherals(withServices: nil)
.map { BlePeripheral(peripheral: $0.peripheral) }
.do(onNext: {
print($0.peripheral.name)
print($0.peripheral.identifier)
print($0.peripheral.connected)
})
}
}
The error is on .filter{ $0 == .poweredOn }
If I remove everything from flatMap
and onwards, the error disappear but obviously I need to have that part at some point. Not sure I understand the error
. I have looked at question/answers on the same error but I'm still not sure how it applies to my case or what the compiler
wants me to do. Appreciate any pointers to how to fix this.
The problem is a type mismatch. The return type of function is Observable<[BluetoothState]>, but inside flatMap return type is Observable<BlePeripheral>