How to mock CBPeripheral data when develop with Core Bluetooth

I'm developing an app which supports for connect with an BLE device. There are some views for showing data from bluetooth. The code below for an example:

    @EnvironmentObject var bleManager: BLEManager // a class implemented CBCentralManagerDelegate
    var body: some View {
        // bleConnected is a CBPeripheral
        if let bleConnected = bleManager.bleConnected {
            if let services = bleConnected.services {
                ForEach(services, id:\.self) { service in
                    // UI for print uuid, descriptions ...
                    showServiceDescriptionView(services)
                    if let characteristics = service.characteristics {
                        ForEach(characteristics, id:\.self) { characteristic in
                            // UI for print uuid, data for each characteristic
                            showCharacteristicsDetailView(characteristic)
                        }
                    }
                }
            }
        }
    }
    
}

But it seems that Xcode Preview do not support connect to a real bluetooth device. So the preview window in Xcode will always be a empty view. I only can see the data on the real device. But it's important for me to design UI on the preview. So are there any method to mock a fake CBPeripheral in the Previewer? Or are there any other way to achieve this?

Probably your best bet would be to create protocols that cover the methods and properties on the CB objects that your code uses, and then conform the CB types to that protocol. Since it already has all the pieces in the protocol it'll conform without further ado.

Then you create your own mock types that also conform to the protocol, and have your Views and ViewModels operate in types of that protocol rather than specific conformers. Does that make sense?

This should then allow you to use your own "mock" types when using Previews.

How to mock CBPeripheral data when develop with Core Bluetooth
 
 
Q