SwiftUI 组合,有没有办法在发送之前添加索引或 uuid

问题描述 投票:0回答:1
var peripheralSubject: PassthroughSubject<CBPeripheral, Never> = .init()

func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
        peripheralSubject.send(peripheral)
    }

此代码给出了 - 要求 AnyCancellable 符合列表中的 randomaccesscollection 错误

有什么办法可以在合并发送之前添加一个id

swiftui conform anycancellable
1个回答
0
投票

据我所知,没有这样的方法,但是可以通过新的结构来控制这种情况。

struct IdentifiedPeripheral: Identifiable {
    let id: UUID
    let peripheral: CBPeripheral
}
© www.soinside.com 2019 - 2024. All rights reserved.